Ctrl + P + Q back to host shell, container detach state
Create a container in which to run the Bash app: sudo docker run-t-i Ubuntu:12.04/bin/bash
List mirrors: Docker images/image ID uniquely identifies a mirror
Create and run the Image: Docker run-t (Assigning a pseudo-TTY)-I (interactive mode) Ubuntu:12.04/bin/bash
Ubuntu is the warehouse name
12.04 is tag
$ sudo docker run-t-i-c 100-m 512mb-h test1-d--name= "Docker_test1" Ubuntu/bin/bash create a CPU priority of 100, memory limit 512MB, host A container named test1 named Docker_test1 running bash in the background specifies the network mode:-net=host/container:name_or_id/none/bridge Host: Use the same IP and port as the host, and the container will not be virtual Plan your own network card and configure your own IP) container: The newly created container shares an IP and port with a container that already exists, does not configure itself, instead of the shared host's None:docker container itself has the network, and does not configure it, it needs to manually add the network card, with IP bridge:docker default network settings, Docker container to Docker0 as a virtual bridge or call routing, all Docker containers are connected to this Docker0, by Docker0 to do routing, by the Docker0 Bridge to assign IP list the main Machine Bridge: yum-y install Bridge-utils/brctl Show uses a specific range of IPs: need to install bridge-utils ensure: 1.
Docker process is stopped: Service Docker Stop/systemctl stop Docker shuts down and uninstalls Docker0 bridge (you can also do without uninstalling) IP link set dev docker0 down Brctl delbr Docker0 2. Create a custom bridge: $ brctl addbr bridge0 $ ip addr Add 192.168.5.1/24 dev Bridge0 $
IP link set dev bridge0 up//ip addr Show Bridge0 view 3. Modify the Docker file to specify the bridge you created $ cat/etc/sysconfig/docker | grep ' options= ' options=--selinux-enabled-b=bridge0-h fd://4. Note If you delete the default
Docker0 bridging, the Docker default bridging is assigned to the BRIDGE0, it is best to add--net=none when creating the container, to prevent the auto-assigned IP from having conflicts in the LAN
Container communication between different hosts:
With: Pipework
git clone https://github.com/jpetazzo/pipework.git
$ sudo cp-rp pipework/pipework/usr/local/bin/
Pipework br0-i eth0 a46657528059 192.168.115.10/24@192.168.115.2
# Default does not specify a network card device name, the default is added as Eth1
# in addition pipework Static routes cannot be added, and if there is a need, you can add--privileged=true permissions to the container manually,
but this security is defective, you can use IP netns to add static routes through IP netns operations to
avoid creating containers Use the--privileged=true option to cause some unnecessary security issues
$ docker inspect--format= "{{. State.pid}} "a46657528059 # Gets the specified container Pid
6350
$ sudo ln-s/proc/6350/ns/net/var/run/netns/6350
$ sudo ip netn s EXEC 6350 IP route add 192.168.0.0/16 dev eth0 via 192.168.115.2
$ sudo ip netns exec 6350 IP route # Add success
Into the Mirror:
Mode 1:docker Attach Con_name attaches the terminal to the terminal of the container that is running the container named Con_name, provided the corresponding SH is specified when the container is created
Way 2:docker Exec-ti Jiedai-op/bin/bash
Turn on/off/kill Image:
Docker start CONTAINER
Stop/t executable time-out
Kill/kill-s Signal Type
Restart/t executable time-out
Pause
Unpause
Rm
Commit commits the specified container as mirrored
Inpect
Logs output specifies container log information-f (similar to tail-f)
Create container without starting
creation: Docker create-t-I centos/bin/bash
run: Docker start-a-I container ID
Search Image: Docker search centos/ubuntu (default download All)
Docker Info: Docker info
Image information: Docker PS (Query-initiated container)/Docker ps-a (View all containers)/Docker ps-as (View all containers and show size)
Pull Image: Docker pulls Centos/ubuntu
Docker pull ubuntu:14.04 Download execute version Ubuntu official image
Equivalent to: sudo docker pull registry.hub.docker.com/ubuntu:12.04
Other sources available: sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04
Push Image: Docker push 192.168.0.100:5000/ubuntu (ubuntu:14.04)
Remove Image: Docker rmi-f (mandatory) Docker.io/ubuntu
Delete Container: Docker rm python_test
Port mapping: Docker run-t-p–expose 22–name Server ubuntu:14.04 (-p need to specify the –expose option when using, specify ports that need to be serviced externally)
Bind port to specified interface: sudo docker run-p 127.0.0.1:80:8080 <image> <cmd>
127.0.0.1 is host ip,80 host port, 8080 container port
sudo Docker run-p 127.0.0.1::8080 <image> <cmd>
sudo docker run-p 80:8080 <image> <cmd>
sudo Docker run-p 8080 <image> <cmd>
binding UDP ports:
sudo docker run-p 127.0.0.1:53:5353/udp <image> < Cmd>
DOCKERFILE: (to be added)
--privileged
Container Data management:
1. Data volumes
2. Data Volume container
sudo docker run--rm--name test-v/source/:/test:ro-t-I ubuntu:14.04/bin/bash
mount the host/source directory under the/test of the container, read-only mode
--RM option: Indicates if test Container has, delete test re-create
Note: /source/cannot be placed in the/root directory of the host, it is recommended to place it in the/home/directory.
Link container:
Using –link
Sudodockerrun−d–namedbtraining/postgres sudo docker run-d–name db training/postgres sudo docker run-d-p–name Web–lin K db:db Training/webapp python app.py
The –link:alias option specifies the container to which the link is linked.
Purpose: To make a link between a Web server and a database server without exposing any ports to external containers, such as:
Container communication between different hosts:
Upload image to hub.docker.com:
1. View the image to be uploaded: (the CentOS image you downloaded, created a container called Centos_test, created a file called Text.txt under Root)
(when submitting the image, the format is: Docker commit-m "Touch a TXT on it "-a" xz295139210 (author) "798adb1953e1 docker.io/xz295139210/centos:v1)
The xz295139210 here is your own hub.docker.com account 798adb1953e1--
This is the centos_test ID of the container container that Docker ps-a found
[ Root@localhost ~]# Docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Xz295139210/python v1 6cd5799caed0 8 seconds ago 687.3 MB
2. Docker Login-- -Verify the account number and password
3. Upload: Docker push docker.io/xz295139210/centos:v1
xz295139210/centos:v1---through Docker images.
Download the image from your hub.docker.com:
1. Docker Login
2. Docker Pull Xz295139210/python:v2
Search Image:
[Root@localhost ~]# Docker Search python
INDEX NAME DESCRIPTION STARS Official automated
Docker.io Docker.io/python Python is a interpreted, interactive, obj ... 1621 [OK]
Docker.io Docker.io/kaggle/python Docker image for Python scripts run on Kaggle [OK]
Naming format: Docker.io/kaggle/python --Kaggle is a user of the Docker image source
Perform actions on the container on the host:
Docker exec can be used to run a process in a container
Docker exec e307f916494c Touch/root/hehe.txt
To label the image:
Docker tag D1e32b95d8e8 192.168.2.67:5000/test
192.168.2.67:5000–> equivalent to the Docker.io of the official warehouse/the address to be uploaded
Test–> is your mirror name.
Tag is different from commit:
tag is mirrored in the source tag
commit is to submit the container as an image
To create a private warehouse upload image:
Error 1:
[Root@localhost ~]# Docker push 192.168.2.67:5000/test
The push refers to a repository [192.168.2.67:5000/test]
Get Https://192.168.2.67:5000/v1/_ping:http:server gave HTTP response to HTTPS client
Resolution 1:
1.cat /etc/docker/daemon.json
{
"Live-restore": True,
"insecure-registries": [" 192.168.2.67:5000 "]
}
2. Restart Docker
Container access control:
1. The container wants to access the external network
1.1 Sysctl Net.ipv4.ip_forward
Net.ipv4.ip_forward = 1
1.2 You can also set the –ip-forward=true when you start Docker, and Docker will automatically set the system Ip_forward parameter to 1
sudo docker # docker command Help
Commands:
Attach attach to a running container # current Shell under Attach connection specify run mirror
Build build a image from a Dockerfile # Dockerfile custom image
Commit Create a new image from a container ' s changes # commit the current container as a fresh mirror
CP Copy files/folders from the containers filesystem to the host path
# Copy the specified file or directory from the container to the host
Create created a new container # Creates a fresh container, same as run, but does not start the container
Diff Inspect Changes on a container ' s filesystem # view Docker container changes
Events get real time events from the server # Get container Live event from Docker service
exec run a command in an existing container # running commands on an existing container
Export Stream the contents of a container as a tar archive
# Export container's content stream as a tar archive [corresponding to import]
History show the historical of an image # show a mirror to form an image
Images list Images # list system current mirror
Import Create A new filesystem image from the contents of a tarball
# Create a new file system image from the contents of the TAR package [corresponding to export]
Info Display system-wide Information # Display system-related information
Inspect Return low-level information on a container # view container details
Kill Kill a Running container # KILL specifies the Docker container
Load load an image from a tar archive # loads a mirror from a tar package [corresponding to save]
Login Register or Login to the Docker registry server
# Register or log in to a Docker source server
Docker login–username=–email=
Logout Log out from a Docker registry server # Exit logs Fetch from the current Docker registry the logs of a container # Output Current container log information port Lookup the public-facing port which is nat-ed to Private_port # view map port corresponding capacitance Internal source port Pause Pause all processes within a container # pause container PS List containers
# List of container lists pull pulls an image or a repository from the Docker Registry server # Extract the specified image or library image from the Docker Mirror source server Push push a image or a repository to the Docker registry server # pushes the specified image or library image to the Docker source server restart restart A running container # Restart the container that is running RM remove one or more containers # Remove a single or multiple container RMI Remove one or more images # removes a mirror or mirrors [no container uses the image for deletion, otherwise the relevant container needs to be removed to continue or-F forcibly removed] Run run a command in a NE
W Container # Create a new container and run a command save save a image to a tar archive # save a mirror as a tar package [corresponding to load] Search Search for a Image on the Docker hub # search for mirrors in Docker hub start start a stopped containers # start container stop Stop a running containers # Stop container tag a image into a repository # give the source a mirror hit Label top Lookup The running processes of a container # view process information running in the container unpause unpause a paused container # Cancel suspend container version show the Docker version information # View Docker build number wait Block until a container
Stops, then print its exit code # intercepts the exit status value when the container is stopped
Run ' Docker command–help ' For more information on a COMMAND.