您的位置:首页 > 运维架构 > Docker

Self-Paced Training (1) - Introduction to Docker

2016-03-27 09:28 671 查看
wget -qo- https://get.docker.com/ | sh

sudo docker run hello-world

sudo usermod -aG docker johnnytu

docker run hello-world

Install Docker

Follow the instructions at https://docs.docker.com/installation/ to install the latest Docker maintained Docker package on your preferred operating system

Run the hello-world container to test your installation: sudo docker run hello-world

Add your user account to the docker group: sudo user mod -aG docker <user>

Logout of your terminal and log back in for the changes to take effect

Verify that you 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

Go to https://hub.docker.com/account/signup/ and signup for an account if you do not already have one

Find your confirmation email and activate your account

Browse some of the repositories

Search for some images of your favorite dev tools, languages, servers etc… examples: Java, Perl, Maven, Tomcat, NGINX, Apache

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

Create a container using the ubuntu 14.04 image and connect to STDIN and a terminal: sudo docker run -i -t ubuntu:14.04 /bin/bash

In your container, create a new user using your first and last name as the username: adducer <username>

Add the user to the sudo group: adducer <username> sudo

Exit the container: exit

Notice how the container shut down

Once again run: sudo docker run -i -t ubuntu:14.04 /bin/bash

Try and find your user

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 be 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

docker run -d centos: 7 ping 127.0.0.1 -c 50

List your containers by running: docker ps

Notice the cents container running

run: docker ps -a

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

docker run -d -P tomcat:7

Check your image details by running docker ps

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

Go to <your linux server url>:<port number> and verify that you can see the Tomcat page
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: