I want to practice Docker on a Windows PC. Since I want to practice on Linux, the first step is to install the virtual machine. I use VMware Workstation 12 Player and ubuntu-16.04-desktop amd64 for the virtual machine file. After installing Ubuntu, if you want to easily transfer files between Windows and Ubuntu, you can add shared folders to the VM Settings as shown below:

To install VMWare Tools, go to the VM menu and choose “Manage” -> Install VMWare Tools. Then go to Ubuntu, find the corresponding tar.gz file in the CD-ROM drive, copy it to a new directory, and unzip it. Run vmware-install.pl in the unzipped directory. After the installation is successful, restart Ubuntu and you will find the added shared folder in/MNT/HGFS.

Once the basic work is done, you are ready to install Docker. Open the console in Ubuntu and perform an update:

sudo apt-get updateCopy the code

Run the following command to install Docker:

sodu curl -sSL https://get.daocloud.io/docker | shCopy the code

The following information is displayed:

Run the docker -v command. The output is as follows: docker version 17.03.0-CE, build 60CCb22

Since this is not a production environment, you are advised to use root as user root. Otherwise, it is troublesome to enter sudo prefix.

Run the sudo passwd root command to reset the password of root.

Run the su – command and enter the root password to switch to user root.

Docker images:

Empty!

Docker images and containers:

Download image:

    docker pull daocloud.io/library/nginxCopy the code
After downloading, execute Docker Images to see the download result:Copy the code

Start: The command to start is

docker run --name nginx001 -idt -P -v /mnt/hgfs/common_dir:/usr/Downloads daocloud.io/library/nginxCopy the code
Run starts a container based on the specified image file --name nginx001 specifies the name of the container after starting. -d: runs in background and returns ID -i: runs the container in intermode. -t: allocates a pseudo-input terminal to the container. Map a port randomly to an open network port inside the container -v/MNT/HGFS /common_dir:/usr/Downloads: Shared file directory, enter the container, the container/usr/Downloads are actually ubuntu/MNT/HGFS common_dir directory, so easy to transfer files daocloud. IO/library/nginx: image file name, is just the one in the downloadCopy the code

Docker ps can be executed to see that the container has been started:

The container is already started, open a browser in Ubuntu and type localhost. Access failed, Unable to connect!

Docker ps command, you can see the following information: 0.0.0.0:32769->80/ TCP: 0.0.0.0:32769->80/ TCP: 0.0.0.0:32769->80/ TCP: 0.0.0.0:32769->80/ TCP: 0.0.0.0:32769->80/ TCP: 0.0.0.0:32769->80/ TCP: 0.0.0.0:32769->80/ TCP Try it, and sure enough, the familiar Welcome page finally appears:

Next go inside the container and execute the command

docker exec -it nginx001 /bin/bashCopy the code
--name nginx001 Specifies the name of the container after it is started. Nginx001: specifies the name of the container, or id /bin/bash: specifies the command executed after it is enteredCopy the code

Now that we are in the container, run cat /etc/issue to see what the system looks like

The shared file path has been set from Windows to Ubuntu vm, and from Ubuntu to Docker container, in order:

E:\work\vm_share\common_dir -> /mnt/hgfs/u16 -> /usr/Downloads

/etc/nginx/nginx.conf. Go back to the Windows E: work\vm_share\common_dir directory and you’ll find the nginx.conf file.

Open the nginx.conf file on Windows and find the line include /etc/nginx.conf.d /*.conf; Comment out the configuration of the line with a #, and add the following statement below the line:

server { server_name localhost; listen 80 default_server; listen [::]:80 default_server ipv6only=on; location / { root html; index welcome.html; }}Copy the code

This configuration is to add a directory to response HTTP requests, and rewrite the default index page and file directory path, after writing and save, back to the docker container, implement cp/usr/Downloads/nginx. Conf/etc/nginx /, Overwrite the nginx configuration file in the Docker container with the modified file;

Create a new HTML file in /etc/nginx/ and run echo “abcdef” > welcome.

Run the service nginx reload command to reload the nginx configuration. Then go to the Ubuntu browser and open localhost:32769 again. You can see that the default page has changed:

If you want to stop the container, you can run the docker stop nginx001 command to stop it. If you want to start the container again, you can run the docker start nginx001 command.

At this point, the preparation, installation and initial experience of Docker are over. In the future, I will combine the usual Java development and deployment work to make more attempts on Docker. I will write a blog for the first time.