Commands:
pull (pulls images)
run (pulls and start)
options
-p <hostport:dockerport>
-d (detached)
--name (name of container)
--net (name of network)
start/stop (restart or stop a container)
ps (list containers)
rm (remove container)
images (list local images)
-v <host:docker folder>
Debugging
docker exec -it <container_name/id> /bin/bash
it - interactive terminal.
docker logs <container_name/id>
start vs run
run creates from image
start restarts container (keep the original arguments passed).
Docker Compose
If more than 1 docker containers needs to be started, create a compose file. This has run for multiple images with a common network. (it is really common)?
It creates a default network and set that for all the containers created.
Commands:
up (start all the images and create the network)
down (stops all the images and remove the network)
Docker File
It is blueprint to create an image. Docker file is so common that it is used by other applications (e.g. ) to create images/.
FROM (First statement of docker is FROM). Each image is created from a base image
ENV (sets the environment for the for the container)
RUN (executes any linux command)
COPY (special command that gets executed on the HOST. Every other commands is executed on the container). COPY <host> <container>
CMD (entry point to the container)
File Name is always DockerFIle
Docker Build
Creates image from the Docker File. There are other image builders such as:??
docker build <(path)docker file>
Docker volumes
To persist the data outside of the container. Container has a virtual file system. This erases when docker is deleted
Volume: A directory form host is mounted to docker file system.
Types of volume:
a. Host Volume -v <hostfolder:dockerfolder>
b. Anonymous
c. -Named volume -v name:<container folder>
e.g. -v name:/var/lib/mysql/data will be converted to -v name /var/lib/docker/volumes/random_host/data:/var/lib/mysql/data
Docker network