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
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
相关文章推荐
- [Docker] - Install Oracle DB over Docker as development DB
- 常用docker命令,及一些坑
- calico docker 应用实例
- Kubernetes安装部署
- 使用fluentd管理docker日志
- docker 实战---部署tomcat\weblogic集群 (二)
- 删除docker0网卡
- Docker相关笔记
- Docker隔绝上传文件
- docker迅速搭建可用 GitLab
- 用P2P方法快速分发Docker镜像
- docker 通过commit方法创建镜像(Tomcat+Java+Scala)
- 庆祝三周年:Docker 推出面向 Mac/Windows 平台的测试版
- Docker网络一览
- 深入理解Docker Volume(二)
- 深入理解Docker Volume(一)
- docker-compose 工具安装
- Docker:镜像的迁移
- 构建最小的docker容器
- 你要知道的Docker应用设计四大关键