Docker first Experience

Source: Internet
Author: User
Tags docker ps docker run

Docker first Experience

In the RoboCup simulation team encountered a very strange problem, the experimental platform is running the environment is java9+, but the agent code of the operating environment is JAVA8 (high version can not). I was going to start a virtual machine to run two different codes, but my roommate told me a better solution to use docker--'s lighter and more efficient solution.

What is Docker

From the Docker Chinese community: Docker is an open source engine that can easily create a lightweight, portable, self-contained container for any application. Developers who compile tests on notebooks can be deployed in batches in a production environment, including VMS (virtual machines), bare metal, OpenStack clusters, and other underlying application platforms.

Why we use Docker

We already have a very mature solution like a virtual machine, so why do we need to use Docker?
At first I understood Docker as a more lightweight, optimized virtual machine, but in fact they were different mechanisms.
To see a very interesting description:

    • Physical machine: A single villa, with a house, independent Foundation, separate garden
    • Virtual machines: An apartment building with many separate suites in one building, all of whom share the building without sharing water and electricity, or entering other people's houses.
    • Container: A building, there are many suites in the building, each suite has a small room, the tenants only have a small room, the same set of tenants sharing all the resources of the suite, can not enter other people's small room.
Give me a chestnut.

Take the case that I have encountered, for example:

    • If I use a virtual machine:
      • Create a virtual machine, install Ubuntu, configure the JAVA10 environment in the virtual machine, run the lab platform
      • Create a virtual machine, install Ubuntu, configure the JAVA8 environment in the virtual machine, run the development platform
    • If I use a docker container:
      • Install an Ubuntu image
      • Create a container, configure the JAVA10 environment, run the experimental platform
      • Create a container, configure the JAVA8 environment, run the development platform

This may still not reflect the characteristics of Docker we will draw a simple diagram (for a more image added a CentOS soul convey online)

Super easy to use getting started installation

Install this little thing, you go to the official website to see ~
PS: I am using deepin15.7 system, install can poke –> Blog

The following actions will take Ubuntu as an example ~

Search/view/Add/Remove mirrors
    • Search Image:docker search ubuntu
    • Download Image:docker pull ubuntu
    • To view all images that have been downloaded:docker images
    • To delete a mirror:
Start a new container
    • docker run -i -t ubuntu:latest

Where parameter-I refers to interactive,-t refers to a temporary terminal

I personally feel more like creating a new container than starting a container, because each container created with the instructions above is different, and here we have to mention a pit: Let's say we create a container and make changes, and the next time you want to use the changed container, you should not use it. docker run docker start, we'll talk about this later.
Since we did not name this container, Docker assigns a random ID to the container, which is thed8a37fb0aaf8

Exit Current Container
    • In the terminal of the container, enter exit orctrl+D
    • (That's not right,,,,)
View Container
    • Docker PS: List all currently running container
    • Docker ps-l: List the most recently launched container
    • Docker ps-a: List all container (including history, running container)
    • Docker ps-q: List the last Run container ID

According to the above docker ps -a command we can see that I have created two containers.

Start and enter the container

As I mentioned above, if I make a change in a container and exit, then I docker run will not enter the container I changed next time, but create a new container, you can try the following code:

docker run -i -t latest /bin/bash# 创建一个容器# 下面的操作是在容器中的操作touch /home/test.txt# 在新容器的home目录下创建一个test.txt文件夹exit# 退出当前容器docker run -i -t ubuntu:latest /bin/bash# 再创建一个容器# 下面的操作是在容器中的操作cd /home# 进入home目录ls# 查看home目录下的所有内容,(当然是空的)

This is why ~ because different containers have their own independent layer of change, different containers are not exchange data drip ~
So if we want to use a container to execute the command is docker start [容器名/容器id] , of course, after the execution of this command is not any reaction, but also add one docker attach [容器名/容器id] , you can also use docker exec -i -t [容器id] /bin/bash ,-> to see the picture

Create a named container

Everything we do above is done through the container ID, but it's tedious to create multiple containers that might be confusing, and docker run we can name them when we do.

docker run docker run -i -t ubuntu:latest /bin/bash

Docker first Experience

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.