Docker discovery-Alibaba Cloud Developer Community

What is Docker?

Docker is the world's leading software containerization platform.

What is a Container?

A standardized unit of software,Package software into standardized units for development, shipment and deployment.

Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.


Docker containers running on a single machine share that machine's operating system kernel; they start instantly and use less compute and RAM. Images are constructed from filesystem layers and share common files. This minimizes disk usage and image downloads are much faster.


Docker containers are based on open standards and run on all major Linux distributions, Microsoft Windows, and on any infrastructure including VMs, bare-metal and in the cloud.


Docker containers isolate applications from one another and from the underlying infrastructure. Docker provides the strongest default isolation to limit app issues to a single container instead of the entire machine.

What is a Container image?

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment.

What is a Repository?

Docker Image Hub

Docker Installations

Install Docker Community Edition (CE) For MAC

$docker -v
$docker info
$sudo usermod -aG docker your_username
$newgrp docker

image acceleration

acceleration Configuration Guide:专用加速地址:如果有阿里云账号,可以使用专属的加速地址

Docker practice

Docker basic commands

$docker run hello-world $docker run -d -p 80:80 --name webserver nginx $docker run --name web -v /source/:/web -it ubuntu:14.04 /bin/bash $docker run --rm --name vol -v /source/:/target:ro -it ubuntu:14.04 /bin/bash $docker run -t -i -d --volumes-from vol --name test1 ubuntu:14.04 /bin/bash

docker run-run a container

-t-assign a (pseudo) tty (link is external)-I-interaction mode (so we can interact with it)-d-background mode ubuntu:14.04-use ubuntu basic image 14.04/bin/bash-run the bash shell-v /host:/container-p hostPort:containerPort -- volumes-from = containerId -- link :alias option to specify the container to be linked.

Common Docker commands

$docker images
$docker search image_id
$docker pull image_id
$docker create -it fedora bash
$docker start container_id
$docker stop container_id
$docker restart container_id
$docker inspect container_id
$docker ps -a
$docker ps -l
$docker top
$docker kill container_id

in-depth exploration of Docker

create an interactive image

$docker run -it --name test ubuntu bash
$docker attach [容器ID|容器名称]
$docker exec -it [容器ID|容器名称] /bin/bash
$xxx blabla ...
$docker differ [容器ID|容器名称]
$docker commit -a "yangdy@" -m "my ubuntu" a404c6c174a2  myubuntu:1.0 
$docker hisotry image_id
$docker cp [容器ID|容器名称]:/container_path to_host_path

network mapping host

$docker run -d    --name db training/postgres
$docker run -d -P --name web --link db:db training/webapp python

port Mapping

docker run -p [([<host_interface>:[host_port]])|(<host_port>):]<container_port>[/udp] <image> <cmd>

$docker run -p <image> <cmd>

automated Docker construction

Automated Build (based on Dockerfile)

  • build instructions
$docker build -t tag .
$docker build --build-arg APP_NAME=appName --pull -f /home/admin/Dockerfile -t
$docker push
# 用基础镜像地址替换下方镜像地址

# 将构建出的主包复制到指定镜像目录中
COPY $APP_NAME.tgz /home/admin/${APP_NAME}/target/${APP_NAME}.tgz
  • basic image
# 基于基础镜像

# 备注

# 定义参数
ARG xxx_version=1.0.0
# 定义基础镜像类型
ENV docker_type="xxx:1.8.0"


RUN rpm -ivh --nodeps "http://rpmHost/xxx1.rpm" && \
rpm -ivh --nodeps "http://rpmHost/xxx2.rpm"

RUN wget -c "http://server/source.tgz" -O /home/admin/target.tgz

## 安装 xxx 脚本
RUN curl -sLk http://server/ | sh

# 将应用启动脚本和nginx配置复制到镜像中
COPY templates/app/bin/ /home/admin/app/bin/
COPY templates/cai/ /home/admin/cai/
COPY templates/ /home/admin/
COPY templates/ /home/admin/

# 设置文件夹操作权限
RUN mkdir /home/admin/logs /home/admin/output /home/admin/diamond /home/admin/cai/logs && \
chmod -R a+x /home/admin/app/bin/ /home/admin/*.sh && \
chown -R admin:admin /home/admin/*

# 挂载数据卷,指定目录挂载到宿主机上面,为了能够保存(持久化)数据以及共享容器间的数据,为了实现数据共享,例如日志文件共享到宿主机或容器间共享数据.
VOLUME /home/admin/logs \
       /home/admin/output \
       /home/admin/cai/logs \
# 容器启动时自动执行的脚本,我们一般会将应用启动脚本放在这里,相当于系统自启应用
ENTRYPOINT ["/home/admin/"]

# 将Aone build的APP_NAME传进来
ONBUILD WORKDIR /home/admin/${APP_NAME}/bin file content

source /home/admin/

rm -f /home/admin/

/home/admin/xxx_app/bin/ restart
echo $code > /home/admin/
exit $code

image history, what happened

$docker history --no-trunc imageId

alibaba Cloud image repository

log on to Alibaba Cloud docker registry:

$ docker login -u dongyu.ydy

the username used to log on to the registry is your domain account. You can click the button in the upper-right corner of the image management homepage to change the docker login password.

Pull an image from the registry:

$ sudo docker pull

push the image to the registry:

$docker tag [ImageId][镜像版本号]
$docker push[镜像版本号]


build a warehouse

LAN construction

docker registry is an open-source code repository. You can directly pull it down and build a code repository on your own. You can also directly use the official code repository of docker-hub. Or use your own service space to build a code repository.

Install the local docker registry

$docker run -d -p 5000:5000 registry

download and start a registry container to create a local private repository service. docker automatically downloads and installs the registry. In this case, we can put some built docker into the local registry.

$docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

Start the local private repository service. Listen to port 5000

submit a docker image

docker push

after the submission is successful, you can check whether the submission is successful on the host.


after that, you can download it from any machine. Use

docker pull ip:5000/test

public network construction

because it is built on this machine, it can only be used in Lan. If you want to make it public, you can build one on the public network. I tried to build one on the Alibaba Cloud ecs instance. The construction process is similar to the above, just need to change the ip address to the public network.

However, note that. docker cannot be installed in the default ubuntu kernel of ECS instances. Upgrade to 3.8.0-25. Upgrade method:

$sudo apt-get install linux-image-3.8.0-25-generic
$sudo apt-get install linux-headers-3.8.0-25-generic

restart again

shutdown -r now


docker help

Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now