Self-Paced Training (1)-Introduction to Docker

Source: Internet
Author: User
Tags docker ps docker hub docker compose docker swarm docker machine

wget-qo-https://get.docker.com/| Sh

sudo Docker run Hello-world

sudo usermod-ag Docker johnnytu

Docker Run Hello-world

Install Docker

    1. Follow the instructions at Https://docs.docker.com/installation/to install the latest Docker maintained Docker Your preferred operating system
    2. Run the Hello-world container to test your Installation:sudo Docker run Hello-world
    3. Add your user account to the Docker Group:sudo user Mod-ag Docker <user>
    4. Logout of your terminal and log back on for the changes to take effect
    5. Verify that can run the Hello-world container without using Sudo:docker run Hello-world

sudo docker version

Docker Machine

Tools that provisions Docker hosts and installs the Docker Engine on them

Docker Swarm

Tools that clusters many Engines and schedules containers

Docker Compose

Tools to create and manage Multi-container applications

Create a Docker Hub account

    1. Go to Https://hub.docker.com/account/signup/and Signup for a account if you don't already have one
    2. Find your confirmation email and activate your account
    3. Browse some of the repositories
    4. Search for some images of your favorite dev tools, languages, servers etc ... examples:java, Perl, Maven, Tomcat, NGINX, Apa Che

Display Local Image

sudo docker images

Creating a Container

sudo docker run [options] [image] [command] [args]

Image is specified with Repository:tag

Examples

Docker run ubuntu:14.04 echo "Hello World"

Docker run Ubuntu PS Ax

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

The-i Flag tells Docker to connect to STDIN on the container

THE-T flag Specifies to get a pseudo-terminal

Run a Container and get Terminal Access

    1. Create a container using the Ubuntu 14.04 image and connect to STDIN and a terminal:sudo docker run-i-T ubuntu:14.04/b In/bash
    2. In your container, create a new user using your first and last name as the Username:adducer <username>
    3. Add the user to the sudo group:adducer <username> sudo
    4. Exit the Container:exit
    5. Notice how the container shut down
    6. Once again Run:sudo Docker run-i-T Ubuntu:14.04/bin/bash
    7. Try and find your user
    8. Notice that it does not exist

Ctrl + P + Q

Container ID

Containers can be specified using their ID or name

Long ID and short ID

Short ID and name can is obtained using Docker PS command to list containers

Long ID obtained by inspecting a container

Running in Detached Mode

Also known as running in the background or as a daemon

Use-d Flag

To observe output use Docker logs <container id>

Docker run-d centos:7 Ping 127.0.0.1-c 50

List Your Containers

    1. Docker run-d centos:7 Ping 127.0.0.1-c 50
    2. List your containers by Running:docker PS
    3. Notice the Cents container running
    4. Run:docker ps-a
    5. Notice all the containers created from the previous exercises

A more Practical Container

Run a Web application inside a container

THE-P flag to map container ports to host ports

Create a container using the Tomcat image, run in detached mode and map the Tomcat ports to the host Port:docker run-d- P Tomcat:7

Run a WEB application Container

    1. Docker run-d-P Tomcat:7
    2. Check your image details by running Docker PS
    3. Notice the port mapping. The container ' s port 8080 is mapped to a random port on your host MACHINE:0.0.0.0:49155->8080/TCP
    4. Go to <your Linux server Url>:<port number> and verify so can see the Tomcat page

Self-Paced Training (1)-Introduction to Docker

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.