博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Self-Paced Training (1) - Introduction to Docker
阅读量:6185 次
发布时间:2019-06-21

本文共 3338 字,大约阅读时间需要 11 分钟。

helloworld:

wget -qo- https://get.docker.com/ | shsudo docker run hello-worldsudo usermod -aG docker johnnytudocker run hello-world

Install Docker

  1. Follow the instructions at https://docs.docker.com/installation/ to install the latest Docker maintained Docker package on 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 in for the changes to take effect
  5. 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

  1. Go to https://hub.docker.com/account/signup/ and signup for an account if you do not 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, 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 axdocker 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 /bin/bash
  2. In your container, create a new user using your first and last name as the username: adduser <username>
  3. Add the user to the sudo group: adduser <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 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

  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 that you can see the Tomcat page 

转载于:https://www.cnblogs.com/thlzhf/p/5324950.html

你可能感兴趣的文章
努力学习
查看>>
安卓学习第一天
查看>>
Oracle expdp数据泵远程导出
查看>>
Trilead,SSH2的Java调用
查看>>
Linux开机自动挂载(磁盘)
查看>>
Python自学笔记之函数式编程5——返回函数
查看>>
乐观锁和悲观锁初步认识
查看>>
MFC中的几个常用类——CWinApp
查看>>
overflow、display、visibility的区别?
查看>>
div 滚动条
查看>>
关于JAVA序列化的一个注意点
查看>>
博客刚建好一定要做好SEO基本工作,方便各大搜索引擎收录!!!
查看>>
RecyclerAdapter封装
查看>>
React Native初探
查看>>
架构学习(二)知识脑图
查看>>
Intent的用法大全
查看>>
1:dubbo集成spring
查看>>
JNI Java层类关联C/C++层的类
查看>>
ubuntu配置jdk,jre同样适用
查看>>
修复桌面小键盘
查看>>