Docker some of the use of the summary __ Sha Box

Source: Internet
Author: User
Tags gz file ssh docker ps docker cp docker run

Because of the Docker used in the analysis of the project, a summary of the use of the search Mirror:

Docker search Mirror name download Image:

Docker pull

Docker pull Learn/tutorial

To write a full mirror name run in Docker hello world

The Docker container can be understood as a process running in a sandbox. This sandbox contains the resources that are necessary for the process to run.

But this sandbox does not run any programs by default.
You need to run a process in the sandbox to start a container, the process is the only process for that container, so
When the process ends, the container is completely stopped.

Docker run has two parameters one is the mirror name and one is the command that runs in the mirror

Docker run learn/tutorial echo "Hello World"
- Install a simple program in the container (ping)

Like Apt-get install-y Ping.

After the Apt-get command has finished executing, the container stops, but changes to the container are not lost.

Note: When executing the apt-get command, take the-y argument, and if you do not specify the-y argument, the Apt-get command
Entering interactive mode requires user input commands to confirm, but it is not possible to respond to this interaction in a docker environment.

Command:

Docker run learn/tutorial apt-get install-y Ping

Save modifications to the container. Commint.

Use the Docker ps-l command to obtain the ID of the container after the ping command was installed. and save this image as learn/ping.

To perform a Docker commit, you can view the list of arguments for the command

You need to specify the ID to commit the Save container (this ID is Docker Ps-l acquired)

This ID is similar to GIT's version number

To execute a command:

Docker commit 698 Learn/ping

The ID number of the new version mirror is returned after execution . Run a new mirror

The new mirror name will be used to run this new mirror. mirroring in the query operation

Docker ps-a View all
docker ps-l view the nearest container
Use the Docker inspect command to view information about a container in more detail

View by ID

To execute a command:

Docker Inspect ID
publish your own mirrors to view all installed mirrors
Docker images
Publish a mirror to the official website
Docker push

This image can only be posted under its own space.

Command: Docker push learn/ping
copy files from the container to the host and copy the files from the host to the container
Docker CP CONTAINER ID: File path save path

docker CP CONTAINER ID container name: File path

Copy it in.

Docker cp/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 bbd4312c781b:/usr/lib64

http://blog.csdn.net/niu_hao/article/details/69546208

To start the mirror, go out the container, and then view the container container ID
Upload a file to the container

Docker container directory hangs in
http://blog.csdn.net/magerguo/article/details/72514813

Docker Run-ti-v/test:/soft Centos/bin/bash

This/test is the host directory, if there is to be deleted, after the colon is soft is the Docker container directory Delete name Tag will none of the container

This is also a reference to the Internet, the address forgot.

Docker Ps-a | grep "exited" | awk ' {print} ' |xargs docker stop
docker ps-a | grep ' exited ' | awk ' {print '} ' |xargs Docker rm
Docker Images |grep None|awk ' {print $} ' |xargs Docker RMI
How to view the name of a container:

Docker PS View the last property is name How to make a container run in the background

The-D parameter used

Using Docker-ti container/bin/bash is interactive into the container
Save changes to the container because otherwise the original mirror state is restored each time it is executed. how to get into a running container.

Docker PS

Gets to the running
Enter

Docker Attach Names

For example

Docker Attach Quizzical_torvalds

will be able to enter the. How to enter the container exit but run in the background.

Ctrl+p+q

Press and hold to exit and the container will continue to run, if exit will close the exit container ... And the previous operation has been restored to the original. And it's all gone. How do I save the operation on the container?

Get commit ID

Gets the commitid of the container to be saved
and then save

Docker commit Commitid a mirrored name saved
dockerfile file Writing, that is, building Docker files

http://blog.csdn.net/yuan_xw/article/details/77744272

A simple example

    1. # This is jdk1.8 + tomcat8.5 Dockerfile 2. # version 1.0 3.   
    # AUTHOR:YUAN_XW 4. 5. # Specifies that the base image is the last modified version of the image. Syntax: from <image>:<tag> 6.   
    From CentOS 7. 8. # maintainer (used to specify the mirror creator information). Syntax: Maintainer <name> 9.   
    Maintainer Yuan_xw 10. One. # Run build instructions, run can execute any commands that are supported by the underlying image.  
    If the base image chooses CentOS, then the Software Management section can only use CentOS commands. RUN Yum install-y wget 13. RUN wget-p/usr/local/software--no-cookies--header "Cookie:oraclelicense=accept-securebackup-cookie;"   
    Download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz 14. # RUN Build instructions, extract jdk-8u144-linux-x64.tar.gz file 16.   
    RUN tar-zxvf/usr/local/software/jdk-8u144-linux-x64.tar.gz-c/usr/local/software 17. # env constructs a directive that sets an environment variable in image. Syntax: ENV <key> <value> 19. ENV java_home/usr/local/software/jdk1.8.0_144 20. ENV CLASSPATH.: $JAVA _home/lib/dt.jar:$Java_home/lib/tools.jar 21.   
    ENV PATH $JAVA _home/bin: $PATH 22. 23. # Install tomcat8.5 24. RUN wget-p/usr/local/software http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.20/bin/ Apache-tomcat-8.5.20.tar.gz 25.   
    RUN tar-zxvf/usr/local/software/apache-tomcat-8.5.20.tar.gz-c/usr/local/software 26. # expose (Specifies the port that the container needs to map to the host machine) sets the directive, which maps the ports in the container to a port in the main machine Cheng. When you need to access the container, you can use the host machine's IP address and the mapped port instead of the container's IP address. To complete the operation requires two steps, first in the Dockerfile use expose set the container port that needs to be mapped, then specify the-p option and the port that expose set when the container is run, so that the expose set port number is randomly mapped Cheng a port number in the main machine. You can also specify which port you want to map to the host machine, and then make sure that the port number on the host machine is not being used.  
    The expose instruction can set multiple port numbers at a time, and the appropriate time to run the container can be matched with the-p option multiple times.   
    Expose 8080 29. #设置tomcat8.5 Start 31. # entrypoint (Set the action to be performed when container starts) 32.  
    # in Docker daemon mode, whether you are using entrypoint, or CMD, the last command, must be the current process needs to be running, to prevent the container from exiting. entrypoint/usr/local/software/apache-tomcat-8.5.20/bin/startup.sh && tail-100f/usr/local/software/  

 Apache-tomcat-8.5.20/logs/catalina.out

Actually, it's very simple ...

The starting from is the underlying mirror image of this image that is defined.
The commands that can be executed after run are used by this mirroring support.

And then you can execute some commands, like I want to build a tomcat &java environment to use
All the way to configure run on it.
HIA can set SSH remote login password user, etc.

You can also configure environment variables directly and container open ports expose 22 is this. Open 22 port

Open the Tomcat port in the same vein.

One of the first internships I've encountered is packing and then building, and mapping this Docker container tomcat 8080 port to the 80 port on the host server

You can also set some of the commands that are executed after the build is completed

is to use entrypoint
Following is the command executed.

# set TOMCAT7 initialization run, SSH Terminal Server runs as background
entrypoint service tomcat7 start &&/usr/sbin/sshd-d

Dockerfile script is written to build a mirror

Docker build-t label.

Notice a little.

When the Docker is run,-D runs in the background. -p to specify port mappings

You can upload the image to register account: login is also docker login

This is just a simple use of dockerfile.

It's just a summary of some simple, commonly used methods or problems with Docker.

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.