Docker 命令行汇总

1.General Docker command

-- List info about the Docker Client:

$ docker version

-- Get docker command help:

---- List all commands:

$ docker --help

---- For a specific command:

$ docker <command> --help


2.Containers

-- List containers:

---- List containers that are up:

$ docker ps

---- List the last started container:

$ docker ps -l

---- List all the containers:

$ docker ps -a

-- Start a container:

$ docker start <container_id>

-- Stop containers:

---- Stop a container:

$ docker stop <container_id>

---- Stop all containers:

$ docker stop $(docker ps -a -q)


-- Restart a container:

$ docker restart <container_id>

-- Remove a container:

$ docker rm <container_id>

-- Delete all containers:

$ docker rm $(docker ps -a -q)

-- Run a container:

---- Run a container:

$ docker run <image_name> <command>

For ex:

$ docker run ubuntu /bin/echo 'Hello world'

---- Run a container in interactive mode:

$ docker run -t -i <image_name> <command>

This will launch a Bash shell inside our container.

---- Run a container in daemonized mode:

$ docker run -d <image_name> <command>

This will run the container and put it in the background, to daemonize it.

-- Commit (save) a container state

$ docker commit <container> <some_name>

-- Get container info:

$ docker inspect <container_id>

Returns a JSON document with configuration and status info.

We can also narrow down the info we want to return by requesting a specific element.

For example, this gives the IP address of the container:

$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container_id>

-- Return container output:

$ docker logs <container_id>

$ docker logs -f <container_id>

-- Examine processes inside a container:

$ docker top <container_id>


3.Images

-- Create an image:

---- Use Dockerfile:

$ docker build -t <username/image_name:tag> .

The -t flag is to identify the new docker image as belonging to <username/image_name:tag>.

. is to indicate use the Dockerfile in the current directory.

---- Use commit command:

$ docker commit -m "<message>" -a "<author>" <container_id> <docker_hub_username>/<image_name>:<tag>

For ex: $ docker commit -m "Added json gem" -a "Kate Smith" 0b2616b0e5a8 ouruser/sinatra:v2

-- List images:

$ docker images

-- Remove an image:

$ docker rmi <image_id>

-- Delete all images:

$ docker rmi $(docker images -q)

-- Pull an image

$ docker pull <image_name>

Pulls an image from docker hub/specified host.

-- Build an image

$ docker build -t <host/img_name:tag> .

Builds an image with specified hostname as prefix.

-- Push an image

$ docker push <username/image_name>

Pushes the docker image to the specified host/docker hub.


4.docker-compose

-- docker-compose build:

Build the containers that the web app and db will live in, and link them up.

-- docker-compose run:

Run one-off commands for services. For example, to see environment variables are available to the web service:

$ docker-compose run web env

-- docker-compose up:

Build, link, and start services.


5.Useful commands

-- Check iptables:

$ sudo iptables -t nat -L -n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值