Note: The server system is centos7, if it is ubuntu, please change the corresponding steps
One, install docker
1. Upgrade package
yum update -y
2. Install docker
yum intsall docker -y
3. Set to start automatically
systemctl enable docker
4. Modify the default installation storage path
Mainly to avoid insufficient space to cause follow-up problems
Docker default installation path/var/lib/docker
Assume that you need to change the installation directory to /data/sdd/docker
and use the method of establishing a soft connection (the attempt to modify the configuration in the text was unsuccessful)
a, close the docker service
systemctl stop docker
b. Copy the previous storage path file to the new directory
cp -rf /var/lib/docker /data/sdd/
c. Back up the original path
mv -u /var/lib/docker /var/lib/docker.bak
d. Establish a soft connection
ln -fs /data/sdd/docker /var/lib/docker
e, open the docker service
systemctl start docker
Two, docker install centos
1. Download the mirror
Select the version to be installed in the centos mirror library , here I choose centos7
docker pull centos:centos7
2. View the mirror
docker image ls
The following information will be displayed
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos centos7 8652b9f0cb4c 2 months ago 204 MB
IMAGE ID is the key, and it will be used later
3. Start the mirror
docker run -p 8050:22 --restart=always --privileged=true -v /data/sda/sharedata:/share -itd 8652b9f0cb4c /usr/sbin/init
-p 8050:22
: Map port 22 in docker-centos to port 8050 of the host for SSH remote login
--restart=always
: Docker restarts automatically after restart
--privileged=true
: Turn on super permissions
-v /data/sda/sharedata:/share
:-V means the shared directory with the host, here means that the /data/sda/sharedata
directory of the host is mapped to the /share
directory
-itd 8652b9f0cb4c
: The image used to start up, where 8652b9f0cb4c is the image ID, which is the previous IMAGE ID
/usr/sbin/init
: Use init to avoid systemctl failure in docker-centos
4. Check the operation of the container
docker ps -a
The following message will appear
CONTAINER ID IMAGE COMMAND CREATED STATUS
56168323adec 8652b9f0cb4c "/usr/sbin/init" About an hour ago Up About an hour
dd0f5f535866 8652b9f0cb4c "/usr/sbin/init" About an hour ago Up About an hour
CONTAINER ID is the key
5. Enter centos
docker exec -it 56168323adec /bin/bash
Among them 56168323adec
is the container ID, which is the CONTAINER ID mentioned above
After pressing enter, enter the terminal of docker-centos
Three, configure centos and realize remote login
1. Upgrade package
yum update -y
2. Install openssl and openssh services
yum install -y openssl openssh-server openssh-clients vim initscripts
Where initscripts
is the installation service
command
3. Modify the ssh configuration file
vim /etc/ssh/sshd_config
Cancel PermitRootLogin yes
comment
Restart the ssh service and ensure that the ssh service is started at boot
systemctl restart ssh_d
systemctl enable ssh_d
4. Use passwd to modify the login password
passwd
5. Use ssh for remote connection
ssh -p [port] root@[ip]
[port]
Host port configured for the previous boot image
[ip]
Host ip
Four, reference
Install Docker-Linux on the server and configure remote login
Docker service and container automatic startup settings after reboot
Two methods to migrate the default installation (storage) directory of Docker
Share files between Docker and the host
Install ssh service in centos7 in docker
Failed to get D-Bus connection: Operation not permitted in Centos7 Docker container