I. Introduction
I have always heard of Docker, it is said to be amazing, so I wanted to see the true face of Lushan a long time ago.
I did an experiment a few days ago. The server installed Centos7, the environment is too backward, I don’t want to toss the environment, so I just took this opportunity to install Docker (Yes, I went to another road to toss ~ V~)
Two, Linux install Docker
I thought that installing Docker would be a road of no return, but the smooth process of installing Docker surprised me. This is one of the reasons why I admire Docker.
Centos
1. Upgrade package
sudo yum update -y
2. Install Docker
sudo yum intsall docker -y
3. Start the Docker background service
sudo service docker start
4. Check the Docker version
docker version
The following words appear
$ docker version
Client:
Version: 1.13.1
API version: 1.26
carry out
Ubuntu (not personally tested)
1. Update the software system
sudo apt-get update
2. Installation dependencies
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
3. Add the official key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Enter to display OK, success
4. Update again
sudo apt-get update
5. Install docker
sudo apt-get install docker-ce
6. View version
docker -v
success
Three, install Linux in Docker
Of course, simple installation is not enough for me to endorse it. What attracts me more is that its function realization reflects a kind of artistic beauty. Nowadays, many things are simpler and more sci-fi
Docker is a container, which separates different software into different processes without interfering with each other
You can install a lot of software in Docker, of course the operating system is also software, so we can install Linux in Docker!
What’s more amazing is its simplicity, like a martial arts master, no trick is superfluous, and it’s not procrastinating.
Let's take Docker-Ubuntu as an example to introduce
1. First pull an ubuntu image from the cloud
sudo docker pull ubuntu
The default is the latest version, but you can also go to the website to choose the version you like >>> Ubuntu mirror library
2. View the mirror
sudo docker image ls
At this time, the corresponding ID will be displayed, and the mirror ID will be used when starting
3. Start the mirror
sudo docker run -itd -p 6789:22 d27b9ffc5667
Meaning: start mirroring in the background, -p means port mapping, map 6789 port to 22 (ssh login port), d27b9ffc5667 is the mirror ID to be started
4. View the started container
sudo docker container ls
You can see that I started two Ubuntu here, which are practical to the same image (the image ID is the same, the container ID and the image ID are not the same thing)
5. Enter the container
sudo docker exec -it ee6281487c44 /bin/bash
ee6281487c44 is the container ID (first column)
Congratulations, you already have an Ubuntu in Docker
But for Linux on the server, of course we want to log in remotely. This is fundamental. Remember the port mapping set before, yes, it is used for ssh remote login.
Fourth, configure ssh remote login in Docker-Ubuntu
1. Enter the container
sudo docker exec -it ee6281487c44 /bin/bash
2. Update and download vim and openssh
apt-get update
apt-get upgrade
apt-get install vim
apt-get install openssh-server
3. Set a password for remote login
passwd
4. Modify the configuration file
vim /etc/ssh/sshd_config
CommentPermitRootLogin prohibit-password
Add toPermitRootLogin yes
Save and exit
5. Restart the ssh service
/etc/init.d/ssh restart
Connect locally
ssh [email protected] -p 6789
success!
Five, afterword
I must have seen it here, and everyone has feelings. It seems that this is indeed an exciting software. When I came into contact with it and learned about it, I was so excited that Amway everywhere, or that is the beauty of minimalism. , Exuding this sci-fi atmosphere from inside to outside
But this is the tip of the iceberg, even the door is not entered, but I still hope that this can stimulate everyone's desire and interest to explore