filmov
tv
Docker Tutorial : What is Docker , How to Install Docker and Docker Basic Commands

Показать описание
In this tutorial i will explain what is Docker and what is a container, i will install it and show the basic commands for Docker.
What is Docker? Create Docker Container and Learn Basic Commands
Written tutorial:
Install Docker
yum install -y docker
If you get below error:
No package docker available.
Try one of below methods:
#1
yum install yum-utils
yum-config-manager –enable rhui-REGION-rhel-server-extras
Or
#2 Find Docker epel repo and download it.
Start the Docker service
RHEL 7 / CentOS 7
systemctl start docker
RHEL/CentOS 5 and RHEL/CentOS 6
sudo service docker start
Add your username to the docker group, if you get an error claiming that group is not there then
create the group manually ‘groupadd docker’
usermod -a -G docker username
You can use below docker commands to confirm installation and other info
service docker status “To confirm that it’s running”
docker –version
docker info
Basic Docker Commands
#1 List available Docker images
docker images
This should return no images as you did not yet install any
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
#2 Search for a specific image inside docker index
docker search ubuntu
–filter “is-official=true” – To show only official images.
docker search centos –filter “is-official=true”
#3 Download image by using ‘docker pull’ and add required version
docker pull centos:6
Confirm docker image download
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
#4 Create docker container
Replace the bold/colored with the required image, in below example i am creating the CentOS 6.9 image
docker images REPOSITORY TAG IMAGE ID CREATED SIZE
docker run -i -t 30365b2e827c /bin/bash
Exit the docker container by typing ‘exit’
#5 Run ‘docker ps -a’ to know the available containers
#6 Start your docker container/instance “replace bold/colored” to the container you want to start by
checking the container id ‘docker ps -a’
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd20a433a852 30365b2e827c “/bin/bash” 2 minutes ago Exited (0) 10 seconds ago fervent_kirch
docker start fd20a433a852
#7 Connect to the docker container
First you have to start the container
docker attach fd20a433a852
Now you are using the CentOS 6.9 system, you can do any modification or update and either ignore it
or commit the changes to the image.
Ex.:
yum install httpd
After installing the httpd and having the configuration changes, you can commit and save all changes
to the image and have it as a new image to be used.
exit “Exit the docker container”
#8 Commit Docker Changes
docker commit fd20a433a852
You can also create that image under new name like “dotsway”
docker commit fd20a433a852 dotsway
By checking docker images you will find your new updated CentOS with the HTTPD installation
under dotsway name.
docker images Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
dotsway latest 636507873058 3 seconds ago 384.7 MB
#9 Remove/Delete an Image
First you have to be sure that the image has no dependent child or being used by stopped container.
docker rmi 30365b2e827c
#10 Remove a Docker Container
docker ps -a “to list all containers”
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64003d7540d1 e12d2e4ec2d7 “/bin/sh -c ‘yum upda” 8 hours ago Exited (1) 8 hours ago stoic_swanson docker rm 64003d7540d1
#11 Stop and remove all Docker’s containers
docker stop $(docker ps -a -q)
What is Docker? Create Docker Container and Learn Basic Commands
Written tutorial:
Install Docker
yum install -y docker
If you get below error:
No package docker available.
Try one of below methods:
#1
yum install yum-utils
yum-config-manager –enable rhui-REGION-rhel-server-extras
Or
#2 Find Docker epel repo and download it.
Start the Docker service
RHEL 7 / CentOS 7
systemctl start docker
RHEL/CentOS 5 and RHEL/CentOS 6
sudo service docker start
Add your username to the docker group, if you get an error claiming that group is not there then
create the group manually ‘groupadd docker’
usermod -a -G docker username
You can use below docker commands to confirm installation and other info
service docker status “To confirm that it’s running”
docker –version
docker info
Basic Docker Commands
#1 List available Docker images
docker images
This should return no images as you did not yet install any
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
#2 Search for a specific image inside docker index
docker search ubuntu
–filter “is-official=true” – To show only official images.
docker search centos –filter “is-official=true”
#3 Download image by using ‘docker pull’ and add required version
docker pull centos:6
Confirm docker image download
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
#4 Create docker container
Replace the bold/colored with the required image, in below example i am creating the CentOS 6.9 image
docker images REPOSITORY TAG IMAGE ID CREATED SIZE
docker run -i -t 30365b2e827c /bin/bash
Exit the docker container by typing ‘exit’
#5 Run ‘docker ps -a’ to know the available containers
#6 Start your docker container/instance “replace bold/colored” to the container you want to start by
checking the container id ‘docker ps -a’
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd20a433a852 30365b2e827c “/bin/bash” 2 minutes ago Exited (0) 10 seconds ago fervent_kirch
docker start fd20a433a852
#7 Connect to the docker container
First you have to start the container
docker attach fd20a433a852
Now you are using the CentOS 6.9 system, you can do any modification or update and either ignore it
or commit the changes to the image.
Ex.:
yum install httpd
After installing the httpd and having the configuration changes, you can commit and save all changes
to the image and have it as a new image to be used.
exit “Exit the docker container”
#8 Commit Docker Changes
docker commit fd20a433a852
You can also create that image under new name like “dotsway”
docker commit fd20a433a852 dotsway
By checking docker images you will find your new updated CentOS with the HTTPD installation
under dotsway name.
docker images Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
dotsway latest 636507873058 3 seconds ago 384.7 MB
#9 Remove/Delete an Image
First you have to be sure that the image has no dependent child or being used by stopped container.
docker rmi 30365b2e827c
#10 Remove a Docker Container
docker ps -a “to list all containers”
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64003d7540d1 e12d2e4ec2d7 “/bin/sh -c ‘yum upda” 8 hours ago Exited (1) 8 hours ago stoic_swanson docker rm 64003d7540d1
#11 Stop and remove all Docker’s containers
docker stop $(docker ps -a -q)