Running the Docker container

There are a number of options for doing this, depending on security requirements, preferences, etc. Here are a few options:

  1. Copying the file with environment variables (recommended)
  2. Using the --env-file flag in docker run
  3. Using the -e flag to add them one-by-one in docker run

When finished, you can then run docker logs -f learning-lab to trail the logs of the running application, to ensure that it has started successfully.

Running the Docker container by copying the .env file

You can create a Docker container without running it, then copy a .env file defining your environment variables into the container. Then start the container's default command by running docker start <container>.

# Create the container, but don't start it yet
docker create --name learning-lab \
              --restart unless-stopped \
              -p 3000:3000 \
              learning-lab

# Copy the .env file from the host into the container
docker cp .env learning-lab:/usr/src/learning-lab/.env

# Start the container
docker start learning-lab

This is the recommended path because it securely stores your environment variables without exposing them in docker inspect, while still providing all the necessary information.

Using docker create and docker cp

You can create a Docker container without running it, then copy a .env file defining your environment variables into the container. Then start the container's default command by running docker start <container>.

# Create the container, but don't start it yet
docker create --name learning-lab \
              --restart unless-stopped \
              -p 3000:3000 \
              learning-lab

# Copy the .env file from the host into the container
docker cp .env learning-lab:/usr/src/learning-lab/.env

# Start the container
docker start learning-lab

This is the recommended path because it securely stores your environment variables without exposing them in docker inspect, while still providing all the necessary information.

Using the --env-file flag in docker run

You can use the --env-file flag to run the Docker image with a .env file included. Note that this may expose your container's environment variables to external services that run docker inspect on your container.

$ docker run --env-file ./env learning-lab

Using the -e flag to add them one-by-one in docker run

By using the -e flag in your docker run command, you can inject each environment variable:

$ docker run -e APP_ID=1 -e WEBHOOK_SECRET=shhhimasecret learning-lab