Docker entry command Daquan

docker installation:

  • Remove the old version:

$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

  • Install some necessary system tools:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

  • Add the software source information:

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

  • Update yum cache:

sudo yum makecache fast

  • Installation Docker-ce:

sudo yum -y install docker-ce

  • Docker start background service

sudo systemctl start docker

  • Hello-world test run

[root@runoob ~]# docker run hello-world

 

  • Modify hub accelerated:

This file is /etc/docker/daemon.json

  • Directly into the modification

{ "Registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn"]}
The following can be replaced with the URL above, individuals prefer HKUST
tutorial article link:
HTTPS: //www.cnblogs. com / ming369 / p / 10711771.html

 

 

 

hello world:

  • docker run ubuntu: 15.10 / bin / echo "Hello world" Run ubuntu: 15.10 Mirror and execute the command xxxx. If this is not a local mirror will go on pull Docker Hub.
  • docker run -i -t ubuntu: 15.10 / bin / bash run an interactive image container
  • docker run -d ubuntu: 15.10 / bin / sh -c "while true; do echo hello world; sleep 1; done" background a container, the container will return ID
  • docker ps can view all images are run
  • docker logs dockerId / dockerName run log can be viewed according to a dockerId
  • docker stop dockerId / dockerName stop a container

 

 Mirroring use:

  • 1. List all the local mirror: docker image ls

REPOSITORY: represents the mirror image of the source warehouse
TAG: image tag
IMAGE ID: Mirror ID
CREATED: Mirror Created
SIZE: image size

Use REPOSITORY: different TAG defined image:
runoob runoob @: ~ $ RUN -t -i Docker Ubuntu: 15.10 / bin / the bash

  • 2. pull a mirror

docker pull ubuntu:13.10

  • 3. Search for a mirror:

docker search httpd

  • 4. Create a mirror

When we downloaded from the docker Mirror Mirror warehouse can not meet our needs, we can make changes to the image in two ways.
A. update image has been created from container and submit this image
B. Use Dockerfile command to create a new image

A: Updating image
docker build, from scratch to create a new image. To this end, we need to create a Dockerfile file
before updating the image, we need to use a mirror to create a container.

docker run -t -i ubuntu: 15.10 / bin / bash
using the apt-get update command to update the operation within the container.
After completing the operation, enter the exit command to exit the container.
We can submit a copy of the container by the commit command Docker:
Docker the commit \
--author "Tao Wang <[email protected]>" \
--message "Modify the default page" \
webserver \
nginx: v2

B: Construction of a mirror
before you update the image, we need to use a mirror to create a container.
CentOS the FROM: 6.7
MAINTAINER Fisher "[email protected]"
RUN / bin / echo 'root: 123456' | chpasswd
RUN useradd runoob
RUN / bin / echo 'runoob: 123456' | chpasswd
RUN / bin / echo -e "LANG = \ "the en_US.UTF. 8-\" "> / etc / default / local
EXPOSE 22 is
EXPOSE 80
the CMD / usr / sbin / -D the sshd

docker build -t runoob/centos:6.7 .

docker history nginx:v2

  • 5.docker tag 860c279d2fec runoob/centos:dev

Mirror docker tag ID, here 860c279d2fec, the user name, source name mirror (repository name) and a new label name (tag).

 

 

 

 Use containers:

docker
docker ps --help
docker ps -a

docker pull nginx

  • Port Mapping

# Full port mapping
Docker RUN -d -P nginx
-d: let container running in the background.
-P: use of the internal container port mapping to the host network we use.

# Custom mapping a port
docker run -d -p 5000: 5000 training / webapp python app.py

View container port mapping:
Docker Port bf08b7f2cd89
Docker Port wizardly_chandrasekhar

  • View container logs

docker logs -f bf08b7f2cd89

  • Check in-process container:

docker top wizardly_chandrasekhar

  • Check containers underlying information

docker inspect wizardly_chandrasekhar

  • Stop the container

docker stop wizardly_chandrasekhar

  • Restart container:

docker start wizardly_chandrasekhar

  • Remove the container

docker rm wizardly_chandrasekhar

  • Log in running container

docker attach 753 is connected to the container terminal while closing the container will start disconnect
docker exec -it 753 / bin / bash start does not affect new container terminal disconnects

  • Start container directly run a command

RUN 84c287 the Java -jar /videobdjob.jar Docker solrIndex
-c is the equivalent proportion is not the real 1024
Docker RUN -m -c 1024M 1024 84c287 the Java -jar /videobdjob.jar solrIndex

  • You can also limit the speed io

Write-RUN Expediting IT --device Docker-bps / dev / SDA: 30MB Ubuntu
bps is byte per second, the amount of write data per second.
iops is the number of times per second, IO per second io.
The container may be controlled by the following parameters bps and IOPS:
--device-Read-bps, a device to limit a read bps.
--device-write-bps, restrict write a device bps.
--device-read-iops, restrict read a device iops.
--device-write-iops, restrict write a device iops.

 

 

 


The container network

(View Bridge brctl show ip addr View Network Network LS Docker)
Container default bridge mode bridge 172.17.0.0/24 the
docker run -d -p 9031: 9031 17d equal docker run -d -p 9031: 9031 --net = bridge 17d

You can see the network information with the host agreement includes a hostname
Docker RUN -dit - Net Host = 17d


Reuse of another container network namespace
docker run -dit --net = container: 70164 5dc


As a virtual machine is not plugged in card
-dit --net = none docker run 5dc48

Specify a subnet and gateway:
Docker Network Bridge --subnet 172.22.16.0/24 --gateway the Create -d 172.22.16.1 mynet

 

 

 

Container file

  • Home directory / var / lib / docker image and container disk space allocation will be noted in this directory
  • builder buildkit containers devicemapper image network plugins runtimes swarm tmp trust volumes

 

 

 

 

docker-nginx installation of:

  • getting Started:

docker search nginx
docker pull nginx
docker images | grep nginx
docker run -i -t --name nginx-test -p 8081:80 -d nginx
curl http://localhost:8081

  • Combat:

Create a local directory, cp or create a file and mount it to the container
$ mkdir -p ~ / nginx / the WWW ~ / nginx / logs ~ / nginx / conf
Docker cp 6dd4380ba708: /etc/nginx/nginx.conf ~ / nginx / conf
vim ~ / nginx / www / index.html

docker run
-d
-p 8082:80
--name runoob-nginx-test-web
-v ~/nginx/www:/usr/share/nginx/html
-v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v ~/nginx/logs:/var/log/nginx nginx

curl http://localhost:8082/index.html

  • To reload NGINX HUP signal may be transmitted to the vessel using the following command:

$ docker kill -s HUP container-name

  • Restart NGINX container command:

$ docker restart container-name

 

 

 

 

docker-mysql installation of:

docker pull mysql
docker -idt --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
docker exec -it mysql-test /bin/bash
mysql -u root -p

  • 1. Authorization

GRANT ALL ON *.* TO 'root'@'%';

 At this point, you can not remote access, because Navicat only support older versions of encryption, encryption rules need to change the mysql

  • 2. Change the encryption rule

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;

  • 3. Update the root user password

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

  • 4. Refresh rights

flush privileges;

 

 

 

 


Creating a local mirror private warehouse

  • 1. Download the warehouse image registry
  • 2. Start the registry container
  • 3. The new profile daemon.json file path: /etc/daemon.json Content: { "insecure-registries": [ "100.2.96.181:5000"]}
  • 4. On the private warehouse uploading and downloading images, need to increase the ip and port name in front of the mirror

e.g docker pull 192.168.0.130:5000/centos:v1

 

Guess you like

Origin www.cnblogs.com/malcolmfeng/p/11327916.html