Docker introduction

1. dockerinstall

#dockerInstallation
sudo apt-get install docker.io

#Method of canceling common user sudo
#1. Create docker group:
sudo groupadd docker
#2. Add the current user to group docker:
sudo gpasswd -a ${USER} docker
#3. Restart service:
sudo service docker restart
#4. Refresh docker members:
newgrp - docker

 

2. image

Find and download mirrors

#Look up the mirror
docker search centos
docker search mysql
#Download mirroring (lastest for mirror version, without specifying default latest)
docker pull mysql:latest
docker pull centos:latest 

Mirror operation

1 # List the mirroring of Downloads
2 docker image ls
3 # delete mirror
4 docker image rm name/id

3. container

Create a container

# Create a container under the specified folder
cd ~/workplace/mysql
docker run -p 3306:3306 --name yu-mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

# Command description:
-p 3306:3306:Map the 3306 port of the container to 3306 of the host. Port.-name yu-mysql:Create a name for the container.-v -v $PWD/conf:/etc/mysql/conf.d:Mount the conf/my.cnf under the host's current directory to the /etc/mysql/ of the container.my.cnf。
-v $PWD/logs:/logs:Mount the logs directory under the host's current directory to the container /logs。
-v $PWD/data:/var/lib/mysql :Mount the data directory under the host's current directory to the /var/lib/ of the container.mysql 。

-e MYSQL_ROOT_PASSWORD=123456:Initialize the password of the root user.

Start stop, delete container

# Starting container
docker start name/id
# Stop container
docker stop name/id
# Deleting container
docker rm name/id

 

View container operation

#View running containers
docker ps
# View all containers
docker ps -a

View the information of the container created

# View container information
docker inspect name/id

Sending instructions to the container

# Inside the container
docker exec -it yu-mysql bash
# Or (I don't want to).
docker attach yu-mysql

# Create a file in the container
docker exec -it yu-mysql touch 123.txt

4. Other operations

Copy files outside containers and containers

# Copy files from containers to containers.
docker cp  yu-mysql:/123.txt   ~/workplace

# Copy the files outside the container to the container.
docker cp  ~/workplace/456.txt  yu-mysql:/

 

The modified container is published as mirroring.

# The modified container is published as a mirror. `-a` represents the author, and `-m` indicates the modification.
docker commit -a "shuai_long" -m "add 123.txt" yu-mysql mysql:0.1

# Creating containers based on new mirrors
docker run --name yu-mysql:01 mysql:0.1

 Private warehouse

Download the image of the repository registration server and create the container.

# Download the mirroring of private repository registry server
docker pull registry:latest

# Create a registry server container
sudo docker run -d -p 5000:5000 --name server-registry -v /tmp/registry:/tmp/registry registry:latest

#Parameter description
 -dThe container is running at the back end.-p 5000:5000Run on the 5000 port of the container and map it to the 5000 port of the external system.--name server-registryThe container is named server-.registry,
 -v /tmp/registry /tmp/registry  Mount Host Directory /tmp/registry to container directory /tmp/registry

Add a label to the local mirror and place it in the local repository.

# Adding labels to local mirrors
docker tag mysql:0.1 localhost:5000/mysql:0.1

#The marked local image, push, to the warehouse.
docker push localhost:5000/mysql:0.1

Testing warehouse availability

#In the virtual machine intranet, open another virtual machine that tries to get the mirror mysql: 0.1 just created from Ubuntu
ifconfig | grep inet

# After getting the IP address
sudo docker pull 192.168.214.156:5000/mysql:0.1

 

Leave a Reply

Your email address will not be published. Required fields are marked *