Install using Docker on CentOS 7

Docker is an open source tool that makes it easy to create and manage Linux containers. Containers are like lightweight virtual machines and can be started or stopped in milliseconds. Docker helps system administrators and programmers develop applications in containers and can scale to thousands of nodes.

The main difference between containers and VMs (virtual machines) is that containers provide process-based isolation whereas virtual machines provide complete isolation of resources. A virtual machine might take a minute to start, while a container takes a second or less. Containers use the kernel of the host operating system, while virtual machines use a separate kernel.

One of the limitations of Docker is that it can only be used on 64-bit operating systems.


In this post we will discuss how to install docker in CentOS 7.x.

Install Docker for CentOS 6/7 series http://www.linuxidc.com/Linux/2014-07/104768.htm


The installation of Docker in CentOS 7 The

Docker package is already included in the default CentOS-Extras repositories. So to install docker, just run the following yum command:

[root@localhost ~]# yum install docker
start the docker service After the

installation is complete, use the following command to start the docker service and set it to start on boot:

[root @localhost ~]# service docker start
[root@localhost ~]# chkconfig docker on
(LCTT Annotation: The old sysv syntax is used here, such as the new systemd syntax supported in CentOS 7, as follows:

[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl enable docker.service


[root@localhost ~]# docker pull centos
Pulling repository centos
192178b11d36:Download complete
70441cac1ed5:Download complete
ae0c2d0bdc10:Download complete
511136ea3c5a:Download complete
5b12ef8fd570:Download complete
确认 CentOS 镜像已经被获取:

[root@localhost ~]# docker images centos
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos5 192178b11d362 weeks ago 466.9 MB
centos centos6 70441cac1ed52 weeks ago 215.8 MB
centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
centos latest ae0c2d0bdc10 2 weeks ago 224 MB
Run a Docker container:

[root@localhost ~]# docker run -i -t centos /bin/bash
[root@dbf66395436d /]#
We can see that the CentOS container has been started and we get the bash prompt. In the docker command we used the "-i capture stdin and output" and "-t assign a terminal or console" options. To disconnect from the container, enter exit.

[root@cd05639b3f5c /]# cat /etc/RedHat-release
CentOSLinux release 7.0.1406(Core)
[root@cd05639b3f5c /]#exit
exit
[root@localhost ~] #We
can also search for containers based on Fedora and Ubuntu operating systems .

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

common commands:
1. View the root user password of the

container docker logs <container name orID> 2>&1 | grep '^User: ' | tail -n1

because the password of the root user when the docker container starts is randomly assigned. So, in this way, you can get the password of the root user of the redmine container.


2. View container logs
docker logs -f <container name orID>

3. View running containers
docker ps
docker ps -a to view all containers, including stopped ones.

4. Delete all containers
docker rm $(docker ps -a -q)

5. Delete a single container
docker rm <container name orID>

6. Stop, start, kill a container
docker stop <container name orID>
docker start <container name orID>
docker kill <container name orID>

7. View all images
docker images

8. Delete all images
docker rmi $(docker images | grep none | awk '{print $3}' | sort -r)

9. Run a new container, Give it a name, port mapping, and folder mapping at the same time. Take the redmine image as an example
docker run --name redmine -p 9003:80 -p 9023:22 -d -v /var/redmine/files:/redmine/files -v /var/redmine/mysql:/var/lib/ mysql sameersbn/redmine

10. One container connects to another
docker run -i -t --name sonar -d -link mmysql:db tpires/sonar-server
sonar

container connects to mmysql container and renames mmysql container to db. In this way, the sonar container can use the relevant environment variables of db.


11. Pull the image
docker pull <image name: tag>

such as

docker pull sameersbn/redmine:latest

12. When you need to migrate the image on one machine to another machine, you need to save the image and load the image.

Machine a

docker save busybox-1 > /home/save.tar

Use scp to copy save.tar to machine b, then:

docker load < /home/save.tar

13. Build your own image

docker build -t <image name > <Dockerfile path>

If the Dockerfile is in the current path:

docker build -t xx/gitlab .

14. Review the stdout of the container
# Start the top command, run in the background
$ ID=$(sudo docker run -d ubuntu /usr/bin/top -b)
# Get the output of the running container
$ sudo docker attach $ID
top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 373572k total, 355560k used, 18012k free, 27872k buffers
Swap: 786428k total, 0k used, 786428k free, 221740k cached
^C$
$ sudo docker stop $ID

115. Run in the background (-d) and expose the port (-p)

docker run -d -p 127.0.0.1:33301:22 centos6-ssh

16. Copy the file from the container

sudo docker cp 7bb0e258aefe:/etc/debian_version .

Copy /etc/debian_version in 7bb0e258aefe to the current directory.

Note: As long as 7bb0e258aefe is not deleted, the file namespace is still there, you can safely copy the container files in the exit state

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326711652&siteId=291194637