docker simple operation and port mapping

One: Introduction

Docker Mirror

Docker in the container based mirroring is activated

Mirroring is the start of the core container

Stratified mirror design, the topmost layer of the reader

COW use snapshot technology to ensure that the bottom is not lost

To see through ifconfig (ip a) docker0 whether there

 

 

docker has been launched successfully

 

II: mirroring operation command

 

 

Note: The last set of commands docker tag or label is not the name changed, but will create a new image

 The above is a summary of some commonly used commands

 

(1) to mysql, for example, using the docker search command

Command: docker search mysql  

 

 

 Where NAME is the name refers to the various versions mysql DESCRIPTION refers to the release notes STARS is whether the official usage OFFICIAL

Look for other software packages is the same operation such as: tomcat

Command: docker search tomcat # is the same

 

 

 

(2) then use a pull command to download image

Command: docker pull tomcat # tomcat download mirror

The figure is seen pull complete success download

We look at command execution docker images

Command: docker images

 

 

Title: REPOSITORY means mirroring warehouse TAG is the version (latest: the latest) IMAGE ID refers to the image ID number CREATED is the time to create SIZE refers to the memory size

 

III: operation command of the container

 

 

 Note: There are a set of commands itd it  

itd: it is on the run in the background

it: is the direct use, once the exit, turn off automatic container

We said before the vessel is based on a mirrored boot, the boot image is the core of the container

Now docker in the container and can not use the ps command to view a list of container

Command: docker ps

 

 

Run container format

Use the format: docker run --name container-name: tag -d image-name

1 .-- name: custom container name is not specified, docker automatically generates a name

2.-d: indicates background container

3.image-name: Specifies the image name and run Tag

 

Now start tomcat

命令:docker run --name Tomcat -d tomcat:latest

 

 

Now is to start a successful, long string of alphanumeric Here is the ID number of the container, then check with the ps command vessel list

1.CONTAINER ID: di container

 

2.IMAGE: Mirror Name: Tag

3.COMMAND: command

4.CREATES: time to create a container

5.STATUS: The current state of the container (up indicates run, Exited means to stop running)

6.PORTS: mirroring port number and protocol used by the program

Note: At this point, although the container has been in operation, Tomcat 8080 port mirroring occupation, but the 8080 is the port inside the Docker container port, not the server,

We must do port mapping maps the actual server port to port in order to access Docker containers.

 

Stop the container

Use docker stop container-name / container-id command to stop operation of the vessel, the name of the specified container or containers may be of id

Command: docker stop 83e141bd0985

ps mean: View the currently running container

ps -a means: All containers should be displayed, with or without running or not running

ps -q means: show only run container

 

 

 

Start container

Start and stop operation of the container using docker start container-name / container-id command can be started the same way according to the name of the container or containers id

Command: docker start 83e141bd0985

 

 

 

Delete container

Before using docker rm container-id command to remove the container, remove the container, the container must be stopped running, remove as container id

rm parameter is to remove the container, rmi parameter is to remove the mirror

Mirror operation in a container, that can run a plurality of non-interfering Docker containers can be run in a mirror with a plurality of containers

Command: docker rm Tomcat

 

 

 

Port Mapping

Use: docker run --name container-name: tag -d -p server port: Docker port image-name

1 .-- name: custom container name is not specified, docker automatically generates a name

2.-d: indicates background container

3.image-name: Specifies the image name and run Tag

4.-p represents port mapping server Docker container, the container occupies default port is mirrored Docker container port are isolated from the outside world, it is mapped to access port

Now open two ports to use iptables

Command: iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
command: iptables -A INPUT -p tcp --dport 8090 -j ACCEPT
command: iptables -L -n # View firewall rule

 

 

Then run the two containers, container names are designated as "Tomcat1", "Tomcat", two vessels are the same tomcat: latest image

Both containers designated port mapping, respectively, 8080,8090, will be forwarded to the internal Docker containers

命令:docker run --name Ttomcat1 -d -p 8080:8080 tomcat:lates

 

命令:docker run --name Ttomcat -d -p 8090:8080 tomcat:latest

 

After a successful start, ip addr show to check the server ip address (192.168.175.102), then you can access from the physical machine

Command: ip addr show

 

Physical machine access 192.168.175.102:8080

 

 

 

 Physical machine access 192.168.175.102:8090

 

 

Container logs

Use docker logs container-name / container-id command to view the container log information, specify the name of the vessel or container id on it

Command: After docker logs Ttomcat # start the container can view the log information

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zgqbky/p/11918044.html