Ubuntu16.04 installing docker1.12+ Development Instance +hello world+web application container

Source: Internet
Author: User
Tags docker ps docker run

This is mainly a detailed record of Docker1.12 on the Ubuntu16.04 installation process, create a Docker group (to avoid the need for each knock command sudo), Docker general summary of BASIC commands, in the container run Hello World, And the entire process of creating a Python-based Flask Web application container.

1.docker1.12 installing on Ubuntu16.04 1.1. Prerequisites 1, adding a Docker source
wxl@wxl-pc:~$ sudo apt-get update

Add CA Certificate

[email protected]-pc:~$ sudo apt-get install apt-transport-https ca-certificates

Add GPG Key (an encryption method)

wxl@wxl-pc:~$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys58118E89F3A912897C070ADBF76221572C52609D

Create a Docker.list file

[email protected]:~$ sudo vim /etc/apt/sources.list.d/docker.list#添加Ubuntu16.04LST的入口deb https://apt.dockerproject.org/repo ubuntu-xenial main

Update Source again

wxl@wxl-pc:~$ sudo apt-get update

Just in case, clear out the outdated source

[email protected]-pc:~$ sudo apt-get purge lxc-docker

Verify that APT is downloading the app from the correct library source

[email protected]-pc:~$ apt-cache policy docker-engine


So far, the source of Docker has been configured

1.2. Prerequisite 2, install the AUFS driver Linux-image-extra

For Ubuntu Trusty, Wily, and xenial, it's recommended to install the Linux-image-extra kernel package. The Linux-image-extra package allows your use of the AUFS storage driver enables the sharing of executables and runtime libraries between containers.

Update the source, you will find Hit:9 Https://apt.dockerproject.org/repo ubuntu-xenial inrelease, and also indicate that Docker was set up successfully in the first step 1.

wxl@wxl-pc:~$ sudo apt-get update

Installing Linux-image-extra

[email protected]-pc:~$ sudo apt-get install linux-image-extra--r)

1.3. Install Docker (if Prerequisites 1, 2 steps are completed correctly)

Update source

wxl@wxl-pc:~$ sudo apt-get update

Install Docker online via apt command

[email protected]-pc:~$ sudo apt-get install docker-engine

Open Docker Daemon (Docker service on)

wxl@wxl-pc:~$ sudo service docker start

International practice, use a Hello world to test the installation success

wxl@wxl-pc:~$ sudo docker run hello-world

Locally there was no Hello World image, acquired through the Docker source, and succeeded in the reality hello.

To view a running container

sudo docker ps -ls

1.4. Create a Docker user group to avoid using sudo

As the first step, "View the running container" if you do not have sudo, running the View container command without root privileges will error cannot connect to the Docker daemon. Is the Docker daemon running on this host?

Reason:
The Docker daemon binds to a Unix socket instead of a TCP port. By default, Unix socket is owned by the user root and other users can access it with sudo. For this reason, Docker Daemon always runs as the root user.

To avoid has the use of sudo when your use of the Docker command, create a Unix group called Docker and add users to it. When the Docker daemon starts, it makes the ownership of the Unix sockets read/writable by the Docker group.

Create a user group Docker to avoid using sudo
Add Docker and WXL (Wang Xiaole username, Default user name is Ubuntu when creating host) to a group

#默认是ubuntu用户#wxl@wxl-pc:~$ sudo usermod -aG docker ubuntu# 将wxl的用户添加到docker用户组中,如果多个用户需要用空格隔开 如 wxl wxl1 wxl2用户wxl@wxl-pc:~$ sudo usermod -aG docker wxl

Note that you will need to restart your computer or log off the user before it can take effect. This makes it unnecessary to use the sudo command.
So, how do I remove WXL from the Docker user group?
sudo gpasswd-d wxl Docker
How do I delete a Docker user group I just created?
sudo groupdel Docker
How to create and delete new users, such as user NewUser
sudo adduser newuser
sudo userdel newuser

1.5. How to update Docker
[email protected]-pc:~$ sudo apt-get upgrade docker-engine
1.6. How to uninstall Docker
[email protected]-pc:~$ sudo apt-get purge docker-engine
2. Run a web App –python flask2.1.docker Simple command summary as follows:
    • Docker run Ubuntu/bin/echo "Hello World"-run Ubuntu image and output "Hello World" in the command window
    • Docker Run-t-I ubuntu/bin/bash-enter Ubuntu This image of the Bash Command window, you can manipulate this image of Ubuntu commands such as LS
    • Docker PS-Lists the currently running containers
    • Docker logs-Display the standard output of the container (e.g. Hello world)
    • Docker stop-Stop a running container
    • Docker version-can view daemons, Docker versions, and go versions (Docker itself is written in go language)

Summary, you can see that Docker commands are generally
[sudo] docker [subcommand] [flags] [arguments]
such as Docker Run-i-T Ubuntu/bin/bash

2.2. Start running Python Flask

Run the Python Flask app (this process can be slow, depending on the speed of the network, because if there is no mirror locally training/webapp:latest will be automatically fetched online)

Complete

View run-in-hit containers via Docker ps-l

Note: Check your port number, it may not be the same as me

Mine is (the terminal is maximized to be easy to identify)

Specify the port number through docker-p, such as change 32769 to 5000

Browser access to http://localhost:80 or http://localhost/

Use the log and top commands according to the container ID or NAMES, as I did when the container ID was 83442361e61b, and NAMES was Reverent_saha

# 按Ctrl+c结束 查看logwxl@wxl-pc:~$ docker logs -f reverent_saha

wxl@wxl-pc:~$ docker top reverent_saha

#返回JSON文档查看配置和状态信息wxl@wxl-pc:~$ docker inspect reverent_saha#通过特定JSON文档的元素查看特定的配置和状态信息,如IPwxl@wxl-pc:~$ ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}‘ reverent_saha

Open/delete/current web App container

#关闭reverent_saha名称为的web应用容器wxl@wxl-pc:~$ docker start reverent_saha#删除reverent_saha名称为的web应用容器(注意,容器必须是stop状态)wxl@wxl-pc:~$ docker rm reverent_saha

Close the Web App container and view the container open status via Docker ps-l

wxl@wxl-pc:~$ docker stop reverent_saha#开启reverent_saha名称为的web应用容器wxl@wxl-pc:~$ docker ps -l

At this point, the open http://localhost/has been unable to link because the Web app is stopped to Python flask.

Ubuntu16.04 installing docker1.12+ Development Instance +hello world+web application container

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: info-contact@alibabacloud.com 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.