install docker on ubuntu
下载安装 http://docs.docker.com/linux/step_one/
1 | $ wget -qO- https://get.docker.com/ | sh |
启动docker
sudo service docker start
验证安装,这个命令将会下载hello-world的image,将运行一个container:
docker run hello-world
如下图
build docker
refer to: http://docs.docker.com/linux/step_four/
edit Dockerfile:
1 | FROM docker/whalesay:latest |
then build with command:
1 | docker build -t docker-whale . |
tag image, for example:
1 | docker tag 7d9495d03763 maryatdocker/docker-whale:latest |
the use docker login
, and the posh the image to docker hub:
1 | docker push maryatdocker/docker-whale |
then you can docker pull
your image:
1 | docker pull yourusername/docker-whale |
also you can remove the image by docker rmi
docker command
1 | docker run # 运行image |
例如,这是docker ps
的例子:
这是docker rm
命令的例子:
container的端口expose或者publish
docker的container中容器的端口expose或者publish到宿主机上, 有一下一些方法:
通过Dockerfile
1 | EXPOSE 7000-8000 |
通过docker run command 1
docker run --expose=7000-8000
或者是publish端口
1 | docker run -p 7000-8000:7000-8000 |
docker命令设置proxy
Edit /etc/defaults/docker
and add the following lines:
1 | export http_proxy 'http://user:password@proxy-host:proxy-port' |
This should allow docker daemon to pull images from the central registry. However, if you need to configure the proxy in the Dockerfile (ie. if you’re using apt-get to install packages), you’ll need to declare it there too.
Add the following lines at the top of your Dockerfile:
1 | ENV http_proxy 'http://user:password@proxy-host:proxy-port' |
With those settings, your container should now build, using the proxy to access the outside world.