"Docker" containers use and mirror production _docker

Source: Internet
Author: User
Tags nginx server docker ps docker hub docker run docker registry
Docker installation

I was installed on Ubuntu 16 Docker,linux installation Docker only need one command:

sudo apt-get install Docker.io

After running, you can enter Docker in the terminal to see the following information to prove that our installation was successful
Note: Add sudo if prompted permission issue

Docker
Usage:docker [OPTIONS] COMMAND [arg ...]
Docker daemon [–help | ...]
Docker [–help |-v |–version]

A self-sufficient runtime for containers.

Options:

–config=~/.docker Location of client config files
-d,–debug Enable Debug Mode
-h,–host=[] Daemon socket (s) to connect to
-h,–help Print Usage
-l,–log-level=info Set the logging level
–tls use TLS; Implied by–tlsverify
–TLSCACERT=~/.DOCKER/CA.PEM Trust Certs signed
–tlscert=~/.docker/cert.pem Path to TLS certificate file
–tlskey=~/.docker/key.pem Path to TLS key file
–tlsverify use TLS and verify the remote
-v,–version Print version information and quit

Commands:
Attach attach to a running container
Build builds an image from a dockerfile
Commit Create a new image from a container ' s changes
CP Copy files/folders between a container and the local filesystem
Create Create a new container
Diff Inspect Changes on a container ' s filesystem
Events get real time events from the server
EXEC Run a command in a running container
Export export a container ' s filesystem as a tar archive
History show the history of a image
Images List Images
Import Import the contents from a tarball to create a filesystem image
Info Display system-wide Information
Inspect return low-level information on a container or image
Kill Kill a Running container
Load load an image from a tar archive or STDIN
Login Register or log in to a Docker registry
Logout Log out from a docker registry
Logs Fetch the logs of a container
Network Manage Docker Networks
Pause pause all processes within a container
Port List port mappings or a specific mapping for the CONTAINER
PS List Containers
Pull pull an image or a repository from a registry
Push push an image or a repository to a registry
Rename Rename a container
Restart Restart a container
RM Remove one or more containers
RMI Remove one or more images
Run Run a command in a new container
Save a image (s) to a tar archive
Search Search the Docker Hub for images
Start start one or more stopped containers
Stats Display a live stream of container (s) Resource usage statistics
Stop stop a running container
Tag tag an image into a repository
Top Display The running processes of a container
Unpause unpause all processes within a container
Update update resources by one or more containers
Version show the Docker version information
Volume Manage Docker volumes
Wait blocks until a container stops, then print its exit code

Run ' Docker command–help ' For more information on a COMMAND.

When you are finished installing, you can also run the following command to view version information:

Docker-v
Docker version
Docker info

When you use Docker run to create a container, the standard actions that Docker runs in the background include checking for a specified mirror on the local level, and not having to download a container from the public repository to create and launch a single file system, and to mount a layer of read-write layers outside the mirrored-only layer Bridging a virtual interface into a container from the Network Bridge interface configured by the host host to configure an IP address from the address pool to execute a user-specified application after execution of the container is terminated

Run container

Once it's installed, we can start a docker trip,

Our present Docker is still a "naked" docker, there is no container, wait a minute, what kind of container. The so-called container is used to run the application in the Docker, the Docker container is very lightweight, but the function is formidable. And no mirrors. Mirror. A simple understanding of a mirror is a read-only version of the container for easy storage and communication. At this point, we can learn by the image provided by the official to us. For example, we want to run an Ubuntu system in Docker, very simply, Docker in the pull command is used to get the mirror, execute the following command, will be from the official warehouse to obtain the Ubuntu 14.04 version of the system:

Docker Pull ubuntu:14.04

The images command is used to view which mirrors exist in the native Docker, and running Docker images will see the Ubuntu14.04 system we just obtained:

Now, we're going to just run the mirror, and the mirror is called a container, and the container is read-write so we can do a lot of interesting things in the container. The Run command is to run the mirror, running:

Docker run-it ubuntu:14.04

Looking closely, you will find that the user name of the terminal interaction has changed, indicating that we have entered the container inside, the effect is as follows:

Now any action we do is for the current container, does not affect the original system, for example, we install the Nginx server inside, run the following command:

sudo apt-get install-y nginx

When you finish executing nginx-v you will find that we have successfully installed the Nginx:

Convert a container to a mirror

In the previous section, we have installed the Nginx in the container, and then we want to save the contents of the container so that we don't have to install it again next time. This is the technique of converting a container into a mirror in Docker.

If you are still in a nginx terminal, perform exit exit from this terminal and return to the system's own terminal:

The PS command can see which containers we are currently running, plus the-a parameter that indicates which containers have been run since we have just exited the container for installing nginx, so I want to see it now, using the-a parameter, to execute the following command:

Docker Ps-a

At this point, we will show the container we just run, and Docker will be very intimate random to each container is a names convenient marking. The effect is as follows:

The commit command is used to convert the container to a mirror, and the following command is run, and we can say that the container has just been converted to mirrors:

sudo docker commit-m "Added Nginx from ubuntu14.04"-a "saymagic" 79c761f627f3 saymagic/ubuntu-nginx:v1

Where the-m parameter is used to specify the descriptive information to be submitted;-a specifies the user's information, the id;saymagic/ubuntu-nginx:v1 of the container 79c761f627f3 the user name, the warehouse name, and the tag information for the target mirror. The ID information for this mirror is returned when the creation is successful. Note that you must change the saymagic to your own username. Because this user name is also used below.

This is when we use the Docker Images command again to find that there is a mirror image we just created:

At this point, if you run Docker run-it Saymagic/ubuntu-nginx:v1 will be a container with Nginx installed:

Storage mirroring

We have just created our own first image, although it's very simple, but it's great, now we want it to be used by more people, and at this point we need to upload this image to the mirrored warehouse, Docker's official Docker hub should be the largest Docker mirror center , so we upload our image to the Docker Hub.

First, we need to be a Docker hub user and go to https://hub.docker.com/for registration. Note that for the convenience of the following, you need to set your username to the same custom username I just mentioned above, for example, I just named the Mirror as SAYMAGIC/UBUNTU-NGINX:V2, so my username is saymagic, Remember the username, password, and mailbox when the registration is complete.

Login defaults to login to the Docker hub, so enter the following command to try to login to the Docker hub:

Docker Login

At this point, will output interaction, let us enter username, Password, Email, successfully entered the information we just registered will return login success hint:

To run the command:

Docker Push SAYMAGIC/UBUNTU-NGINX:V1

That's why we've named the image saymagic/ubuntu-nginx:v1, and if you're doing the right thing in the previous steps, you'll get the following:

At this point, no accident, our mirror has been uploaded to the Docker hub above, to the Docker hub to look at:

Sure enough, we had our first image on the Docker hub, at which point other users could get an Ubuntu system with Nginx installed directly by ordering Docker pull Saymagic/ubuntu-nginx. Don't believe it. Then practice it yourself.

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.