Docker tips and Common commands and docker tips

Source: Internet
Author: User
Tags docker ps
Docker usage skills and common commands, docker usage skills
Install docker

Check whether the curl package is installed?

which curl
If curl is not installed, update the apt source first and install curl as follows:

apt-get updateapt-get install curlapt-get updatewget -qO- https://get.docker.com/ | sh
Set the current user as the docker user group, which is convenient to solve the need to enter a password every time the docker command is executed.

# Add a new docker user group groupadd docker # Add the current user to the docker user group. Note that xxoo here is the ubuntu server login user name gpasswd -a xxoo docker # Restart the docker background monitoring process service docker restart # After restart, try it , Whether it takes effect docker version # If it has not yet taken effect, the system restarts, then takes effect reboot
Start the docker service as follows:

service docker start
Common commands
Run container

        docker run hello-world
Show local mirror

       docker images
Get mirror

       docker pull ubuntu: 12.04
Create a container and let it run bash

          docker run -t -i ubuntu: 12.04 / bin / sh
            Explanation: -i: means to run the container in "interactive mode" -t: means that the container will enter its command line after starting.

Use DocFile to create an image

         mkdir sinatracd sinatra / touch Dockerfilevim Dockerfiledocker build -t = "ouruser / sinatra: v2".
Run container

        docker start [stop | restart] xxx
Export container

           docker ps -adocker save -o ubuntu.tar.gz ubuntu: 14.04 * (Save the version record of all this image, including some historical data.) * docker export pid> ./ubuntu.tar.gz * (Export is (The image content currently used by the container) *
Import container

          docker load </tmp/mynewimage.tar * (reverse operation of docker save) * cat ubuntu.tar | docker import-test / ubuntu: v1.0 * (reverse operation of export) *
Delete container

          docker stop xxx docker rm xxx
            Note: docker files are placed in / var / lib / docker / containers /.

Save image

     docker commit xxx abc
         Note: This is saved as a mirror named abc. Only lower case letters and numbers are allowed in the mirror name.

Delete mirror

      docker rmi abc
Get mirror history

         docker history abcdocker images --tree * (view the history of all images) *
           Note: This command can only be executed on a locally existing docker image.

Kill one or more specified container processes

         docker kill container
           Description: -s "KILL" customizes the signal sent to the container.

View a running container process

          docker top container
            Note: ps command parameters are also supported.

Suspend all processes in a container

        docker pause container
Resume all processes of a container

           docker unpause container
Mark a local mirror and put it in a warehouse

             docker tag image name
              Explanation: -f overwrites the existing mark.

Get the output log of the container runtime

         docker logs container
docker attach

      docker run -itd ubuntu: 14.04 / bin / bashdocker attach 44fc0f0582d9
         Note: docker attach can attach to the stdin of an already running container, and then perform the command execution action. However, it should be noted that if you exit from this stdin, it will cause the container to stop.

docker exec

      docker exec -i name / bin / sh
          When only -i is used, since there is no pseudo terminal assigned, it looks like pipe execution. But the execution result and command return value can be obtained correctly.

      docker exec -it name / bin / sh
         When using -it, it is similar to our usual console interface. And it will not cause the entire container to withdraw due to the attachment method.

        docker exec -t name / bin / sh
            If you only use the -t parameter, you can see a console window, but when you execute the command, you will find that you cannot see the execution of the command because you don't get the output of stdin.

       docker exec -d name / bin / sh a.sh
           Perform a process in the background. It can be seen that if a command takes a long time to process, the -d parameter will return quickly. The program runs in the background.

Hierarchical display of information for an image or container

         docker inspect 465c60612e5c
Common container installation
mysql

       docker search mysql
       docker pull mysql
        docker run --name xmysql-db -e MYSQL_ROOT_PASSWORD = root -d -p 3306: 3306 -v / data / mysql_data /: / var / lib / mysql mysql
mongodb

      docker pull mongo
      docker run --name xmongo-db -p 27018: 27017 -v / data / my_mongo_data: / data / db -d mongo
jenkins

         docker pull jenkinschown 1000 / data / jenkins_data /
        docker run --name xjenkins -d -p 9000: 8080 -p 50000: 50000 -v / data / jenkins_data: / var / jenkins_home -e JAVA_OPTS = -Duser.timezone = Asia / Shanghai --env JAVA_OPTS = "-Xmx512m- XX: PermSize = 256m -XX: MaxPermSize = 1024m "-d jenkins
elasticsearch

      docker pull elasticsearch
      docker run --name xelastic-search -d -p 9200: 9200 -p 9300: 9300 -v / data / esdata: / usr / share / elasticsearch / data elasticsearch
tomcat

        docker pull tomcat
       docker run --name xtomcat -d -v / data / tomcat / webapps /: / usr / local / tomcat / webapps / -p 8080: 8080 -p 9001: 9000 tomcat: 8
dockerui

        docker run -d -p 9000: 9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock dockerui / dockerui
webgoat

      docker pull webgoat / webgoat-7.1
     docker run --name xwebgoat -d -p 8080: 8080 webgoat / webgoat-7.1

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.