Docker binaries are incorporated into RHEL/CentOS 7 extras repositories, the installation process being pretty simple.
# yum update # yum install epel-release && yum update # yum install docker # yum install -y python-pip # pip install docker-compose
# systemctl start docker # systemctl enable docker
# docker run hello-world
If you can see the below message, then everything is in the right place.
"Hello from Docker. This message shows that your installation appears to be working correctly."
Now, you can run a few basic Docker commands to get some info about Docker:
# docker info
→ For system-wide information on Docker# docker version
→ For Docker version# docker
→ To get a list of all available Docker commands type docker on your console.In order to start and run a Docker container, first an image must be downloaded from Docker Hub on your host. Docker Hub offers a great deal of free images from its repositories.
# docker search ubuntu
# docker pull ubuntu
# docker images
# docker rmi ubuntu
When you execute a command against an image you basically obtain a container. After the command that is executing into container ends, the container stops (you get a non-running or exited container). If you run another command into the same image again a new container is created and so on.
All the containers created will remain on the host filesystem until you choose to delete them by using the docker rm command.
# docker run ubuntu cat /etc/issue
The above command is divided as follows:
# docker run [local image] [command to run into container]
# docker ps -l
# docker start c629b7d70666
# docker stop dreamy_mccarthy # docker ps
# docker run --name myname ubuntu cat /etc/debian_version
# docker start myname # docker stats myname # docker top myname
Be aware that some of the above commands might display no output if the process of command that was used to create the container finishes. When the process that runs inside the container finishes, the container stops.
In order to interactively connect into a container shell session, and run commands as you do on any other Linux session, you can go further like this:
# docker run -it ubuntu bash
The above command is divided as follows:
-i is used to start an interactive session.
-t allocates a tty and attaches stdin and stdout.
ubuntu is the image that we used to create the container.
bash (or /bin/bash) is the command that we are running inside the Ubuntu container.
# exit
If you’re interactively logged on container terminal prompt and you need to keep the container in running state but exit from the interactive session, you can quit the console and return to host terminal by pressing Ctrl+p and Ctrl+q keys.
Issue docker ps command to get the ID or name
and, then, run docker attach
command by specifying container ID or name, as illustrated in the image above: # docker attach <container id>
# docker kill <container id>
That’s all for basic container manipulation. In the other tutorial we will discuss how to save, delete and run a web server into a Docker container.