ubuntu16.04server install dockerCE

Source: Internet
Author: User
Keywords Ubuntu system ubuntu command dockerCE installation tutorial
Tags access added an application application applications apt apt-get archive

ubuntu16.04server install dockerCE.

Docker is an application that makes it simple and easy to run applications in containers, just like virtual machines, which are only more portable, more resource-friendly, and more dependent on the host operating system. To learn more about the different components of a Docker container, see Docker Ecosystem: An Introduction to Common Components.

There are two ways to install Docker on Ubuntu 16.04. One way is to install it on an existing operating system installation. Another way is to use a tool called the Docker machine to automatically install Docker on the server. In this tutorial you will learn how to install and use it on an existing Ubuntu 16.04 installation.

Preparation conditions

64-bit Ubuntu 16.04 server

Non-root users using sudo privileges, Ubuntu 16.04 Initial Setup Guide explains how to set this up.

Note: Dockera requires a 64-bit version of Ubuntu and a kernel version equal to or greater than 3.10. The default 64-bit Ubuntu 16.04 server meets these requirements.

All commands in this tutorial should be run as non-root users. If the command needs root access, it will precede sudo. The initial setup guide for Ubuntu 16.04 explains how to add users and give them access to sudo.

Step 1 - Install Docker

The Docker installation package provided in the official Ubuntu 16.04 repository may not be the latest version. To get the latest and greatest version, install Docker from the official Docker repository. This section shows you how to do this.

First, add the GPG key to the official Docker repository: curl -fsSL sudo apt-key add-apt-repository is a Python-software- properties sudo apt-get sudo apt-get sudo sudo apt-get sudo sudo apt-get sudo sudo add-apt-repository sudo apt-get sudo apt-get sudo sudo add- apt-repository "deb [arch = amd64] https://download.docker.com/linux/ubuntu $ (lsb_release -cs) stable" Next, update the package database using the Docker package from the newly added repo: sudo apt- get update Make sure you're installing Docker repo instead of the default Ubuntu 16.04 repo: sudo apt-cache policy docker-ce

You should see output similar to the following:

docker-ce: Installed: (none) Candidate: 17.03.1 ~ ce-0 ~ ubuntu-xenial Version table: 17.03.1 ~ ce-0 ~ ubuntu-xenial 500 500 https://download.docker.com/linux/ ubuntu xenial / stable amd64 Packages 17.03.0 ~ ce-0 ~ ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial / stable amd64 Packages Note that Docker-ce is not installed, but the candidate for installation From the Docker repository on Ubuntu 16.04. Docker - ce version number may be different. Finally, install docker: sudo apt-get install -y docker-ce Docker should now be installed, daemon started, the process started. Check the run: sudo systemctl status docker

The output should look similar to the following, showing that the service is active and working:

docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) since: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks ago Docs: https://docs.docker.com Main PID: 749 (docker) Installing Docker now provides not only Docker service (daemon), Docker command line utility, or Docker client . We will explore in this tutorial how to use the docker command. Step 2 - Do Not Use Sudo (Optional) Execute Docker commands

By default, running the docker command requires root permissions-that is, you have to prefix sudo to the command. It can also be run by users in the docker group, which is automatically created when docker is installed. If you try to run the docker command without having to pre-set it in a sudo or docker group, you get this output:

docker: Can not connect to the Docker daemon. Is the docker daemon running on this host ?. See 'docker run --help'. If you want to avoid typing sudo when running docker commands, add your username to the docker group : sudo usermod -aG docker $ {USER} To apply the new group membership, you can quit the server and go back, or you can type the following: su - $ {USER} You will be prompted to enter your user's password to continue. You can then confirm that your user is now added to the docker group by typing: id -nG If you need to add your unregistered user to the docker group, declare the username as: sudo usermod -aG docker username The remainder of this article assumes You run the docker command in the docker user group. If you choose not to use, please sudo pre-orders.

Step 3 - Use the Docker command

With Docker's installation and work, it's time to become familiar with the command line utilities. Using docker includes passing a series of options and commands, followed by parameters. Syntax uses this form: docker [option] [command] [arguments]

To see all the available subcommands, type: docker

In Docker 1.11.1, the complete list of available subcommands includes:
Output

attach Attach to a running container build Build an image from a container's changes cp Copy files / folders between a container and the local filesystem create Create a new container diff Inspect changes on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on a container or image kill Kill a running container load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container network Manage Docker networks pause Pause all processes within a container port List port mappings or a specific mapping for the CONTAINER ps List containers pull Pull an im age or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart a container rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive search Search the Dock Hub for images start Start one or more stopped containers stats Display a live stream of container (s) resource usage statistics stop Stop a running container tag Tag an image into a repository top Display the running processes of a container unpause Unpause all processes within a container update Update configuration of one or more containers version Show the Docker version information volume Manage Docker volumes wait Block until a container stops, then print its exit code To view the switches that are available for a specific command, type : docker docker-subcommand --help To see system-wide information about Docker, use: docker info Step 4 - Using a Docker Image

Docker container is run by Docker image. By default, it extracts these images from the Docker registry managed by Docker Hub (Docker). Docker is the company behind the Docker project. Anyone can build and host their Docker images on the Docker Hub, so most applications and Linux distributions need Docker containers to run on the Docker Hub.

To check if you can access and download images from Docker Hub, type: docker run hello-world

The output that should include the following should indicate that Docker is working correctly:

Output Hello from Docker. This message shows that your installation appears to be working correctly. ... You can search for images available on the Docker Hub by using the Docker command to search for subcommands. For example, to search for an Ubuntu image, type: docker search ubuntu

The script will grab the Docker Hub and return a list of all images whose name matches the search string. In this case, the output will be similar to the following:

Output NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s ... 3808 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 61 [OK] torusware / speedus-ubuntu Always updated official Ubuntu docker imag ... 25 [OK] rastasheep / ubuntu-sshd Dockerized SSH service, built on top of of ... 24 [OK] ubuntu-debootstrap debootstrap --variant = minbase --components ... 23 [OK] nickistre / ubuntu-lamp LAMP server on Ubuntu 6 [OK] nickistre / ubuntu-lamp-wordpress LAMP on Ubuntu with wp-cli installed 5 [OK] nuagebec / ubuntu Simple always updated Ubuntu docker images ... 4 [OK] nimmis / ubuntu This is a docker images different LTS vers ... 4 [OK] maxexcloo / ubuntu Docker base image built on Ubuntu with Sup ... 2 [OK] admiringworm / ubuntu Base ubuntu images based on the official u ... 1 [OK ] ... In the official column, OK represents the image of the company behind the project build and support. Once you have identified the image you want to use, you can download it to your computer using the Razor command, for example: docker pull ubuntu After downloading the image, you can run a subcommand to run a container using the downloaded image. If you do not download an image while docker is executing a run subcommand, the docker client will first download the image and then use it to run a container: docker run ubuntu To view the image downloaded to your computer, type: docker images

The output should look similar to the following:

As you'll see in this tutorial, the image you use to run the container can be modified and used to generate new Images, and then upload those images to the Docker Hub or other Docker registries (technical terms). Step 5 - Run the Docker container

The hello - world container you ran earlier is an example of a container that runs and exports after the test message is issued. However, containers may be more useful than this, and they can be interactive. After all, they are similar to virtual machines, but more resource-friendly.

As an example, let's run a container using the latest image from Ubuntu. The combination of i-t switches allows you to access the container through an interactive shell: docker run -it ubuntu Your command prompt should change to reflect the fact that you are working in a container and should take the following form: Output root @ d9b100f2f636: / # Important: Notice the container id in the command prompt. In the above example, it is d9b100f2f636. Now you can run any command inside the container. For example, let's update the package database inside the container. You do not need to prefix any command with sudo because you are operating in a container with root privileges: apt-get update and then install any application in it. For example, let's install node. Js. apt-get install -y nodejs Step 6 Submit the changes in the container to the Docker image

When you start the Docker image, you can create, modify, and delete files just as you would a virtual machine. Your changes will only apply to this container. You can start and stop it, but once you use the docker rm command to destroy it, the change will be lost forever. This section shows you how to save the status of a container as a new Docker image.

** After installing nodejs in an Ubuntu container, you now have a container that runs from the image, but the container is different from the one you used to create it.
To save the state of the container as a new image, first exit from it: ** exit Then use the following command to submit the changes to the new Docker image instance. - The m switch is a submit message that helps you and others know about your changes, and - a is for the specified author. The container ID is the one you mentioned earlier when you started an interactive docker session. The repository is usually your Docker Hub user name unless you have created an additional repository on the Docker Hub: docker commit -m "What did you do to the image" -a "Author Name" container-id repository / new_image_name

E.g:

docker commit -m "added node.js" -a "Sunday Ogwu-Chinuwa" d9b100f2f636 finid / ubuntu-nodejs Note: When you submit an image, the new image is saved locally, that is, on your computer. Later in this tutorial, you'll learn how to push images to the Docker registry, such as the Docker Center, so you and others can evaluate and use it. After the operation is completed, listing Docker images on your computer should show the new image, along with the old image it came from: docker images

The output should look like this:

Ubuntu-nodejs latest 62359544c9ba 50 seconds ago 206.6 MB ubuntu latest c5f1cf30c96b 7 days ago 120.8 MB hello-world latest 94df4f0ce8a4 2 weeks ago 967 B In the example above, ubuntu - nodejs is a new image that comes from the Docker Hub Ubuntu image. The difference in size reflects the change. In this example, the change is NodeJS installed. So next time you need to run a container using Ubuntu with NodeJS Preinstalled, you're ready to use the new image. Images can also be built from so-called Dockerfiles. But this is a very complex process that is beyond the scope of this article. Step 7 - List Docker Containers After using Docker for some time, you will have many active (inactive) and inactive containers on your computer. To view the event, use: docker ps

You will see output similar to the following:

Output CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f7c79cc556dd ubuntu "/ bin / bash" 3 hours ago Up to 3 hours silly_spence To view all containers - active and inactive, go through - a switch: docker ps -a To view The latest container you created, pass in the - l switch: docker ps -l Stopping or Active The container is as simple as typing: docker stop container-id The container id can be found in the docker ps command's output. Step 8 - Push the Docker image to the Docker repository

The next logical step after creating a new image from an existing image is to share it with your friends, the world's Docker Hub, or other Docker registries that you can access. To push an image to the Docker center or to any other Docker registry, you must have an account there.

** This section shows you how to push Docker images to the Docker Center. To learn how to create your own private Docker registry, check out how to set up a private Docker registry on Ubuntu 14.04.
To create an account on the Docker Hub, sign up at the Docker Center. Then, push your image to Docker Hub. You will be prompted for authentication: ** docker login -u docker-registry-username If you specify the correct password, authentication should succeed. Then you can use: docker login -u docker-registry-username

It takes some time to complete and when done, the output will look similar to the following:

Output The push refers to a repository [docker.io/finid/ubuntu-nodejs] e3fbbfb44187: Pushed 5f70bf18a086: Pushed a3b5c80a4eba: Pushed 7f18b442972b: Pushed 3ce512daaf78: Pushed 7aae4540b42d: Pushed ... After the image is pushed to the registry, it should be there The account is listed on the dashboard, as shown in the image below.



If a push attempt resulted in this error then you may not be logged in:

Output The push refers to a repository [docker.io/finid/ubuntu-nodejs] e3fbbfb44187: Preparing 5f70bf18a086: Preparing a3b5c80a4eba: Preparing 7f18b442972b: Preparing 3ce512daaf78: Preparing 7aae4540b42d: Waiting unauthorized: authentication required Log in, then repeat the push attempt. Conclusion There is more to Docker than this one, but that's enough to get you started using it on Ubuntu 16.04. Like most open source projects, Docker is built from a rapidly developing code base, so get in the habit of accessing project blog pages for up-to-date information. You can also view other Docker tutorials in the DO community.
Related Article

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.