docker Flashcards
To turn and image into a container and enter its shell, type
docker run -it –name container-name image-name
To list all live running containers, type
docker ps
To exit a docker container’s shell without shutting it down, type
control P Q
A docker container is basically
a daemon thats running an image. Treat it like its own computer.
To enter the shell of a particular container, type
docker attach container-name
To shut down a container from inside it’s terminal, type
exit
To see all your downloaded docker images, type
docker images
To delete an image, type
docker rmi -f image-name
To delete a container, type
docker rm -f container-name
Am image is
all the code of the OS, the environment dependencies, and your app code
To create a new image, you need to
create a Dockerfile
The FROM section in the Dockerfile defines
which base image you will copy from dockerhub.
The EXPOSE section in the Dockerfile defines
the port that your container will be allowed listen to.
Otherwise it will ignore
To build a docker image based on your application code, and the Dockerfile, type
docker build -t my-image-name .
this is if my files are local in . and my .Dockerfile is in .
To pass requests from port 8000 on my computer to port 8000 in my computer, type
docker run -p 8000:8000 image-name
To make a docker container accept requests on a particular port, you need to
put EXPOSE 8000 in the dockerfile so it will be permitted to listen
run the container with docker run -p 8000:8000 image-name so requests to my computer are forwarded to the container
For development, to get updates to project files to get seen by the docker image, you need to use
a volume
a volume is
a path to a directory that your container will be able to access in real time from your main computer in its container. A portal.
A dockerfile is basically
the list of instructions for creating a new docker image
Before deploying, you must
remove your volume and create a new image with the files actually copied into the image.
Volumes do not
save into the image.
The COPY section in the dockerfile defines
files to copy from the local computer to the container computer.
e.g. COPY myDir /myContainerDir
The CMD section in the dockerfile defines
a command you want to run in the container’s WORKDIR
Must be a list of arguments
e.g. CMD [‘echo’, ‘string’]
Docker closes the container if
Process ID 1 exits
The process for using this with django might be
Create a dockerfile from a python3 image
create a volume for my app files
create a command for pip install -r requirements.txt
Then create the container from the image, and add the port to the run command.
then run runserver
https://www.youtube.com/watch?v=hnxI-K10auY
the WORKDIR section in the dockerfile defines the
path to a folder automatically created by docker, and where your commands will run from
the ADD section in the dockerfile defines
a file that you want copied into
ADD and COPY are the same except
ADD can also accept a URL