What is Docker
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
IMAGES
An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization.
CONTAINERS
A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.
Install Docker Centos
# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
# yum sudo makecache
# yum install docker-ce --nobest
# systemctl enable docker
# systemctl status docker
# systemctl start docker
# docker run hello-world
# docker (list all command options)
# docker search browser (search for an image)
# docker pull centos (this will download an image to your local Docker repository)
# docker images (this will show all images stored onto your Docker repository)
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 300e315adb2f 5 days ago 209MB
hello-world latest bf756fb1ae65 11 months ago 13.3kB
# docker run centos cat /etc/hosts (To run a command inside the centos container and exit)
# docker ps -l (This will list containers)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf8ddd1911bb centos "cat /etc/hosts" About a minute ago Exited (0) About a minute ago fervent_bose
# docker start cf8ddd1911bb (Re-run the same container using existing container ID)
# docker stop cf8ddd1911bb (this container is alread in exit state, but if you want to stop a running container use the command 'STOP')
# docker images (this command shows all images stored on your Docker repository)
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 300e315adb2f 5 days ago 209MB
hello-world latest bf756fb1ae65 11 months ago 13.3kB
Interactive SHELL within a container
# docker run -it centos bash (this command will start the container and initiate a BASH SHELL where you can interact with the container)
#exit and it will stop the container
# Keep container running and exit to host
<Ctrl>+<p> <Ctrl>+<q>
# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7cf9311ecd3a centos "bash" About a minute ago Up About a minute jovial_carver
# docker attach 7cf9311ecd3a (To connect back to the container use the container ID)
# docker stop 7cf9311ecd3a (to stop a container)
# docker kill 7cf9311ecd3a (to kill a container)