Installing and using Docker on Ubuntu

Source: Internet
Author: User
Tags docker ps docker hub docker run docker registry

About Docker:

Docker is an open source project that provides developers and system administrators with an open platform, anywhere by packaging and running applications as a lightweight container. Docker deploys applications automatically within the software container. Docker started with Solomon Hykes as an internal development project for DotCloud, an enterprise-class PaaS (platform as a service platform), which is now maintained by the Docker community and Docker, and more D Ocker information you can visit: https://docs.docker.com/.

Key words for Docker:

A.docker Images

  Docker Image is the most basic template for Docker container. Image Universal container makes the system and application easy to install, Docker image is used to run the container, you can find many images (various operating systems and software already installed Docker) here https://hub.docker.com/.

B.docker Container

The Docker container (Docker Container) is an image that reads and writes on a running Docker Image. Docker is a federated file system as a container behind the scenes, and any changes to the container will be saved on a basic image new layer. The layer where we install the application is the container. Each container running on the host machine is independent, thus providing a secure application platform.

C.docker Registry

  Docker Registry is a library for Docker images. It provides both public and private libraries. The public Docker library is called the Docker Hub. Here we are able to upload push and pull our own images.

And then we started installing Docker on the Ubuntu system.

To run the install Docker command:

sudo Install -y Docker.io

Wait for the installation to complete, start Docker with the following command

sudo systemctl start docker

Enable Docker when running system boot

sudo systemctl enable Docker

If you want to view the version of Docker, enter the following command

Docker version

Now let's talk about the basic uses of Docker.

In this section, I'll show you the common options for Docker commands. For example, how to download a docker image, create a container, and how to access the container.

To create a new container, you should choose a basic image of the operating system, such as starting Ubuntu or CentOS or other systems. You can search for a basic image using the Docker Search command:

Docker search Ubuntu

This command will show all Ubuntu images, you can try it yourself to search for CentOS images.

Below we base image into our server

Docker pull Ubuntu

You can now view all downloaded images by command:

Docker images

Ubuntu images are downloaded from Dockerhub/docker registry. The next step is to create a container from that image.

To create a container, you can use the docker create or Docker run

Docker Create ubuntu:14.04

The docker create command creates a new container, but does not start it. So now you need to use the Run command:

Docker Run-i-T Ubuntu:14.04/bin/bash

This command creates and runs a container based on the Ubuntu14.04 image, and runs a command/bin/bash inside the container, and you will run the command automatically within the container.

When you exit the container by entering the exit command, the container also stops running, and if you want the container to run in the background you need to add the-d parameter after the command.

Docker run-i-t-d Ubuntu:14.04/bin/sh-c "while true; do echo Hello world; Sleep 1; Done

/bin/sh-c "while true; do echo Hello world; Sleep 1; The "This is Bash script to echo " Hello word " forever".

Now you can see the container running through the command in the background:

Docker PS

If you want to see the log results from the Bash command, use the command:

Docker logs Names/containerid

How do I access the container shell in the background? This command will connect your container shell:

Docker Exec-i-T Names/containerid

You can see that the host name and container ID are equal, which means you are inside the container shell. When you type ' exit ' on the shell, the shell will leave, but the container is still running.

Another command that you will often use is:

Docker Stop Name/containerid

This will stop the container without deleting it, so you can restart it with the command:

Docker start Name/containerid

If you want to delete the container, first stop it and then use the command to delete it:

Docker RM Name/containerid

Installing and using Docker on Ubuntu

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.