Basic usage of Docker.

sudo docker build -t tc-informix .
sudo docker run -it --name iif_developer_edition --privileged -p 9088:9088 -p 9089:9089 -p 27017:27017 -p 27018:27018 -p 27883:27883 -e LICENSE=accept tc-informix

images

sudo docker images

rmi

sudo docker rmi $(sudo docker images -q -f dangling=true)

run

sudo docker run -it --rm ubuntu:14.04 bash

ps

sudo docker ps
sudo docker logs [container ID or NAMES]

rm

docker rm $(docker ps -a -q)

start, stop, attach

sudo docker stop d457395b35e2
sudo docker ps -a
sudo docker start d457395b35e2
docker exec -it d457395b35e2 bash
sudo docker attach nostalgic_hypatia

logs

sudo docker logs -t iif_developer_edition

日志文件位于 var/lib/docker/containers/<container_id>,文件名为 <container_id>-json.log

Dockerfile

touch Dockerfile
FROM nginx
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html

Docker has a default entrypoint which is /bin/sh -c but does not have a default command.

When you run docker like this: docker run -i -t ubuntu bash the entrypoint is the default /bin/sh -c, the image is ubuntu and the command is bash.

The command is run via the entrypoint. i.e., the actual thing that gets executed is /bin/sh -c bash. This allowed docker to implement RUN quickly by relying on the shell’s parser. Later on, people asked to be able to customize this so ENTRYPOINT and -entrypoint has been introduced.

An other example would be to have any cli as entrypoint. For instance, if you have a redis image, instead of running docker run redisimg redis -H something -u toto get key, you can simply have ENTRYPOINT ["redis", "-H", "something", "-u", "toto"] and then run like this for the same result: docker run redisimg get key.

When the operator executes docker run --privileged, Docker will enable to access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host.


install

sudo apt-get install docker-engine
sudo service docker start
sudo docker run hello-world

service

Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sudo service docker start
sudo docker build -t tc-cache .

pull

sudo docker pull ubuntu:14.04

commit

sudo docker pull nginx
sudo docker run --name webserver -d -p 80:80 nginx
sudo docker exec -it webserver bash
echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
exit
sudo docker diff webserver
sudo docker commit \
    --author "Tao Wang <twang2218@gmail.com>" \
    --message "修改了默认网页" \
    webserver \
    nginx:v2
sudo docker images nginx
sudo docker history nginx:v2
sudo docker run --name web2 -d -p 81:80 nginx:v2

build

docker build -t nginx:v3 .

因此,COPY 这类指令中的源文件的路径都是相对路径。这也是初学者经常会问的为什么 COPY ../package.json /app 或者 COPY /opt/xxxx /app 无法工作的原因,因为这些路径已经超出了上下文的范围,Docker 引擎无法获得这些位置的文件。如果真的需要那些文件,应该将它们复制到上下文目录中去。

export

sudo docker export 7691a814370e > ubuntu.tar
cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0