1. Overview Flashcards
What is a Dockerfile?
A text document that contains all the commands a user could call on the command line to assemble a docker image.
What is the use of a .dockerignore file?
It allows you to exclude files from the context like a .gitignore file allow you to exclude files from your git repository. It helps to make build faster and lighter by excluding from the context big files or repository that are not used in the build.
How do you specify what docker image to use as a template in a Dockerfile?
By using the FROM command.
eg. FROM node
How do you specify the work directory to be created in a Dockerfile?
By using the WORKDIR command.
eg. WORKDIR /usr/src/app
How do you copy a file or multiple files from the root of the project into the workdir in a Dockerfile?
By using the COPY command.
eg. COPY package*.json ./
How do you run an npm command in a Dockerfile?
By using the RUN command.
eg. RUN npm install
How do you copy the entire root content of a project into the work directory in a Dockerfile?
By using the COPY command.
eg. COPY . .
How do you specify a port to be exposed in a Dockerfile?
By using the EXPOSE command.
eg. EXPOSE 4000
How do you specify a default command to be executed in order to run the app in the container in a Dockerfile?
By using the CMD commad.
eg. CMD ["npm", "start"]
Can you have more than one CMD commands in a Dockerfile?
No. Only the last CMD will take effect.
How do you create a new Docker image using a Dockerfile?
By executing the docker build
command after having specified the image name via the -t
flag, and the directory that the Dockerfile is in.
eg. docker build -t atlaskaplan/simple-backed .
PS. the dot (.) at the end means that the Dockerfile is in the current directory.
How do you list all the Docker images you created alongside their IDs, creation dates, tags, and sizes in the commandline?
By executing the docker images
command.
eg. docker images
How do you delete a Docker image from your system?
By executing the docker rmi
command and specifying the image ID.
eg. docker rmi e30b45e15491
How do you run a Docker image?
By executing the docker run
command having specified the port using the -p
flag and specifying the Docker image’s name.
eg. docker run -p 4000:4000 atlaskaplan/simple-backend
How do you stop a running Docker container?
By executing the docker stop
command with the Docker container’s ID or name.
eg.
docker stop d56bf8342cfa
ORdocker stop container-name