nuxt-docker

Building a Docker image to run Nuxt 3 Apps

MIT License

Stars
0
Committers
1

Nuxt 3 and Docker

This repository shows how you can build an image of your Nuxt app and create a container running it. Additionally, it shows how to handle env variables while building the image and running a container.

Building and running

How to build an image

First of all make sure you have Docker installed.

To build an image run the following command in the project root.

docker build  -t nuxt/docker-demo:latest .

This command builds an image following the specifications in the Dockerfile using the standard .env file due to not excluding it.

How to start a container from the image

Create and run a new container from the image you just build by running:

docker run -p 3000:3000 nuxt/docker-demo:latest

How to start the container with different env variables

As long as you follow the naming conventions for the runtime config specified in the nuxt documentation you can do so as such:

docker run --env NUXT_PUBLIC_SOME_VALUE="hello there!" -p 3000:3000 nuxt/docker-demo:latest

or as such

docker run --env-file ./.env.run -p 3000:3000 nuxt/docker-demo:latest

Quick Docker reminder

You can list your images by running:

docker images

You can delete an image by running:

docker rmi <image_id>

You can list your containers by running:

docker ps -a

You can stop a containers by running:

docker stop <container_id>

You can list delete a container by running:

docker rm <container_id>

Additional resources