Install docker and ubuntu

Source: Internet
Author: User
Tags gpg docker ps docker cp docker registry

Install docker and ubuntu

Docker

Environment:

Centos 6.5 64-bit

If the system is installed by default, the centos kernel is

[Root @ localhost ~] # Uname-
Linux localhost. localdomain 2.6.32-431. el6.x86 _ 64

 

 

Docker supports 64-bit kernel for versions 3. xx and later.

 

 

1. First, upgrade your own kernel level 2.6-"3.xx

Steps:

[Root @ localhost ~] # Rpm-ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Warning:/var/tmp/rpm-tmp.mbaRhP: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ######################################## ### [100%]
1: epel-release ##################################### ###### [100%]

[Root @ localhost ~] # Rpm -- import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

123 cd /etc/yum.repos.dwget http://www.hop5.in/yum/el6/hop5.repoyum install kernel-ml-aufs kernel-ml-aufs-develUpdate Kernel

Modify/etc/grub. conf

Default = 1 to 0. By default, the kernel will be updated after restart.

 

[Root @ localhost ~] # Yum-y install docker-io

 

2. Start docker first and then start it automatically.

[Root @ localhost ~] # Service docker start
Starting cgconfig service: [OK]
Starting docker: [OK]
[Root @ localhost ~] # Chkconfig docker on

Obtain the CIDR block of a CIDR Block

[Root @ localhost ~] # Docker pull centos: latest
Centos: latest: The image you are pulling has been verified
2017136ea3c5a: Pull complete
5b12ef8fd570: Pull complete
34943839435d: Downloading [==>] 18.38 MB/232.5 MB 110000m49s

# Official installation method: docker pull imagename is downloaded from the docker index center. imagename is the image name. For example, docker pull Ubuntu downloads base ubuntu and the tag is latest.

We can also search for containers based on the Fedora and Ubuntu operating systems.

[Root @ localhost ~] # Docker search ubuntu
[Root @ localhost ~] # Docker search fedora

View docker Images

[Root @ localhost ~] # Docker images centos
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Centos latest 34943839435d Less than a second ago 224 MB

Run docker and run shell

[Root @ localhost ~] # Docker run-I-t centos/bin/bash
[Root @ 2ce733141ece/] #
[Root @ 2ce733141ece/] #
[Root @ 2ce733141ece/] #
[Root @ 2ce733141ece/] #

Stop container

[Root @ localhost ~] # Docker stop <container id>

Delete all containers

Docker rm $ (docker ps-a-q)

View the sub-commands of docker and directly press docker or complete docker help.
 
Common commands

To sum up the Common commands:

The <> width parameter is required, and the [] width parameter is optional.

• View the docker version, including the client, server, and dependent Go.

Docker info: View System (docker) information, including the number of managed images and containers.

Docker search <image> search for image in docker index

Docker pull <image> drop down the image from the docker registry server

Docker push <image | repository> pushes an image or repository to the registry

Docker push <image | repository>: The TAG is the same as the preceding one. Specify the tag.

Docker inspect <image | container>: view the underlying information of the image or container.

Docker images TODO filter out the intermediate image layers (what is intermediate image layers)

Docker images-a lists all images

Docker ps displays the running iner by default.

Docker ps-l displays the last created iner, including

Docker ps-a displays all the containers, including those not running

Docker logs <container> displays the logs of the container, that is, some output of the command.

Docker rm <container...> delete one or more container

Docker rm 'docker ps-a-Q' delete all container

Docker ps-a-q | xargs docker rm same as above, delete all container

Docker rmi <image...> deletes one or more images.

Docker start/stop/restart <container> enable/stop/restart container

Docker start-I <container> starts a container and enters the interaction mode.

Docker attach <container> attach a running container

Docker run <image> <command> use image to create a iner, execute the corresponding command, and then stop

Docker run-I-t <image>/bin/bash: Use image to create a container and enter the interactive mode. The login shell is/bin/bash.

Docker run-I-t-p

Docker commit <container> [repo: tag] restores a container into a new image, and the repo: tag is optional.

Docker build <path> looks for the Dockerfile in the path, and uses this configuration to generate a new image

Docker build-t repo [: tag] is the same as above. You can specify a repo and an optional tag.

Docker build-<dockerfile> use the specified dockerfile configuration file. docker obtains the content in stdin mode and uses this configuration to generate a new image

Docker port <container> <container port> to check which local port is mapped to the specified port of the container. docker ps can also be used to view

Docker mounts the host machine directory to the docker container.

[Root @ linuxidc ~] # Docker run-t-I-v/root/convirt-install: /mnt/convirt docker.cn/docker/centos:centos5/bin/bash # mount the host directory to the container-t indicates that the Pseudo Terminal is allocated-I indicates that the host directory is run interactively-v indicates the local directory: the following is the container directory.
[Root @ fe943ba99287/] # df
Filesystem 1K-blocks Used Available Use % Mounted on
Rootfs 10190136 530928 9118536 6%/
/Dev/mapper/docker-253: Container
10190136 530928 9118536 6%/
Tmpfs 989592 0 989592 0%/dev
Shm 65536 0 65536 0%/dev/shm
/Dev/mapper/vg_linuxidc-LogVol01
49212216 19620096 27069192 43%/etc/resolv. conf
/Dev/mapper/vg_linuxidc-LogVol01
49212216 19620096 27069192 43%/etc/hostname
/Dev/mapper/vg_linuxidc-LogVol01
49212216 19620096 27069192 43%/etc/hosts
/Dev/mapper/vg_linuxidc-LogVol01
49212216 19620096 27069192 43%/mnt/convirt
Tmpfs 989592 0 989592 0%/proc/kcore
[Root @ fe943ba99287/] # cd/mnt/convirt/
[Root @ fe943ba99287 convirt] # ls
Common convirt-install-2.1.1.tar.gz install
 

Create a container and submit an image

Install the program in the container and submit it to the image

Install AN httpd In the docker container for testing and exit after installation.

[Root @ linuxidc ~] # Docker ps-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Fe943ba99287 docker.cn/docker/centos:5 "/bin/bash" 17 minutes ago Exited (0) 20 seconds ago distracted_archimedes
Remember container ID

Submit container to image

[Root @ linuxidc ~] # Docker commit fe943ba99287 web # submitting a container to the image web is the name of the image
49bc0d42b01698a462868f2ecaedfec267fed02c393f1ad06ec17b0d1012eff2
[Root @ linuxidc ~] # Docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Web latest 49bc0d42b016 54 seconds ago 532.9 MB # This is the submitted Image
Docker.cn/docker/centos 5 bac0c97c3010 3 weeks ago 466.9 MB
Docker.cn/docker/centos centos5 bac0c97c3010 3 weeks ago 466.9 MB
Centos 6 510cf09a7986 3 weeks ago 215.8 MB
Centos S6 510cf09a7986 3 weeks ago 215.8 MB
Docker.cn/docker/centos 7 8efe422e6104 3 weeks ago 224 MB
Docker.cn/docker/centos centos7 8efe422e6104 3 weeks ago 224 MB
Docker.cn/docker/centos latest 8efe422e6104 3 weeks ago 224 MB

Port ing Boot Image

[Root @ linuxidc ~] # Docker run-d-p 80: 80 -- name apacheWEB web: latest/etc/init. d/httpd start
Bytes

Docker images

Show image list

Docker ps

Display container list

Docker run IMAGE_ID

Specify the image to run a container

Docker start/stop/pause/unpause/kill/restart CONTAINER_ID

Operation container status

Docker tag IMAGE_ID [REGISTRYHOST/] [USERNAME/] NAME [: TAG]

Name a specified Image

Docker pull/push NAME: TAG

Download and push the image to the Docker registry server. The NAME part includes the service address.

Docker rm/rmi CONTAINER_ID/IMAGE_ID

Delete a container or image

Docker inspect CONTAINER_ID/IMAGE_ID

View Details

Docker top CONTAINER_ID

View the process of the specified running container

Docker info

View system configuration information

Docker save/load

Save and restore Image Information

Docker commit CONTAINER_ID

Create an image from a container

Docker export> xxx.tar

Save a container

Docker import-<xxx.tar

Restore A Container

Docker cp CONTAINER_ID: PATH HOSTPATH

Copy files from images to physical machines

Docker diff CONTAINER_ID

View the file changes of the container relative to the image

Docker logs CONTAINER_ID

View container logs

Docker build

Build an image from Dockerfile

Docker history IMAGE_ID

View image building history

 

NOTE: If docker cannot be started

[Root @ localhost ~] # Service docker status
Docker is dead, but the pid file is still saved

First, check whether your kernel version number is correct. If it is not updated, update it.

[Root @ localhost ~] # Yum upgrade device-mapper-libs
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* Base: pai.lzu.edu.cn
* Epel: mirror. premi. st
* Extras: pai.bit.edu.cn
* Updates: 2.16.lzu.edu.cn
Setting up Upgrade Process
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-libs.x86_64. 02.79-8. el6 will be updated
--> Processing Dependency: device-mapper-libs = 1.02.79-8. el6 for package: device-mapper-1.02.79-8.el6.x86_64
---> Package device-mapper-libs.x86_64. 02.117-7. el6_8.1 will be an update
--> Running transaction check
---> Package device-mapper.x86_64. 02.79-8. el6 will be updated
--> Processing Dependency: device-mapper = 1.02.79-8. el6 for package: device-mapper-event-1.02.79-8.el6.x86_64
---> Package device-mapper.x86_64. 02.117-7. el6_8.1 will be an update
--> Running transaction check
---> Package device-mapper-event.x86_64. 02.79-8. el6 will be updated
---> Package device-mapper-event.x86_64. 02.117-7. el6_8.1 will be an update
--> Processing Dependency: device-mapper-event-libs = 1.02.117-7. el6_8.1 for package: device-mapper-event-1.02.117-7.el6_8.1.x86_64
--> Running transaction check
---> Package device-mapper-event-libs.x86_64. 02.79-8. el6 will be updated
---> Package device-mapper-event-libs.x86_64. 02.117-7. el6_8.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================== ========================================================== ========================================================== ========================================================== ==============================
Package Arch Version Repository Size
========================================================== ========================================================== ========================================================== ========================================================== ==============================
Updating:
Device-mapper-libs x86_64 1.02.117-7. el6_8.1 updates 256 k
Updating for dependencies:
Device-mapper x86_64 1.02.117-7. el6_8.1 updates 211 k
Device-mapper-event x86_64 1.02.117-7. el6_8.1 updateles 133 k
Device-mapper-event-libs x86_64 1.02.117-7. el6_8.1 updateles 125 k

Transaction Summary
========================================================== ========================================================== ========================================================== ========================================================== ==============================
Upgrade 4 Package (s)

Total download size: 725 k
Is this OK [y/N]: y
Downloading Packages:
(1/4): device-mapper-1.02.117-7.el6_8.1.x86_64.rpm | 211 kB
(2/4): device-mapper-event-1.02.117-7.el6_8.1.x86_64.rpm | 133 kB
(3/4): device-mapper-event-libs-1.02.117-7.el6_8.1.x86_64.rpm | 125 kB
(4/4): device-mapper-libs-1.02.117-7.el6_8.1.x86_64.rpm | 256 kB
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 121 kB/s | 725 kB
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating: device-mapper-libs-1.02.117-7.el6_8.1.x86_64 1/8
Updating: device-mapper-1.02.117-7.el6_8.1.x86_64 2/8
Updating: device-mapper-event-libs-1.02.117-7.el6_8.1.x86_64 3/8
Updating: device-mapper-event-1.02.117-7.el6_8.1.x86_64 4/8
Cleanup: device-mapper-event-1.02.79-8.el6.x86_64 5/8
Cleanup: device-mapper-event-libs-1.02.79-8.el6.x86_64 6/8
Cleanup: device-mapper-1.02.79-8.el6.x86_64 7/8
Cleanup: device-mapper-libs-1.02.79-8.el6.x86_64 8/8
Verifying: device-mapper-event-1.02.117-7.el6_8.1.x86_64 1/8
Verifying: device-mapper-event-libs-1.02.117-7.el6_8.1.x86_64 2/8
Verifying: device-mapper-1.02.117-7.el6_8.1.x86_64 3/8
Verifying: device-mapper-libs-1.02.117-7.el6_8.1.x86_64 4/8
Verifying: device-mapper-1.02.79-8.el6.x86_64 5/8
Verifying: device-mapper-event-libs-1.02.79-8.el6.x86_64 6/8
Verifying: device-mapper-event-1.02.79-8.el6.x86_64 7/8
Verifying: device-mapper-libs-1.02.79-8.el6.x86_64 8/8

Updated:
Device-mapper-libs.x86_64 0: 1. 02.117-7. el6_8.1

Dependency Updated:
Device-mapper.x86_64. 02.117-7. el6_8.1 device-mapper-event.x86_64. 02.117-7. el6_8.1 device-mapper-event-libs.x86_64. 02.117-7. el6_8.1

Complete!

[Root @ localhost ~] # Service docker restart
Stop docker: [OK]
Starting docker: [OK]
[Root @ localhost ~] # Service docker status
Docker (pid 3692) is running...
[Root @ localhost ~] #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.