Lab for learning about Docker
- Docker for Windows: https://store.docker.com/editions/community/docker-ce-desktop-windows
- A text editor such as Visual Studio Code: https://code.visualstudio.com/
- Postman (for sending POST requests to the app): https://www.getpostman.com/apps
To speed up the class, please download the Docker images we'll be using ahead of time by using these commands:
docker pull node:alpine
docker pull redis
docker pull microsoft/aspnetcore-build:latest
docker pull microsoft/aspnetcore:latest
-
Start a Docker container that uses the
-v
flag to create a volume that serves a node.js app -
Create a Dockerfile that:
- Uses the
node:alpine
image - Uses
RUN npm install
- Uses
CMD ["npm", "start"]
- Copies the current directory's files into the image
- Order the commands to make use of layer caching
- Uses the
-
Use build arguments and labels in the Dockerfile to:
- Add metadata, such as the version number of the image being built
-
Use environment variables to:
- Inject an environment variable into the container at runtime
- Change the environment variable with
docker run
to change the text displayed on the webpage
-
Use a .dockerignore file to:
- Prevent files such as the Dockerfile from being copied into the image
-
Create a Docker network named "mynet"
-
Create a Redis container and the node.js app and use
--network
to put them both on the "mynet" network -
Put the name of the Redis server into the node.js container by using the
-e
flag to pass in an environment variable