docker command line summary

docker command line summary

image: a read-only file system consisting of a base layer and a series of difference layers

container: a writable file system consisting of an image and a top writable layer with network and volume hooks

    Note:
  • an image has id, name, tag, read-only_layers, entrypoint, and cmd
  • a container has id, name, source_image, writable_layer, overwrite_cmd, cpu_limit, memory_limit, volume_hook, network_hook, and state (active/un-active)
what docker can do with images in a local image store
  -- creation --
  - import/export with docker hub
   search in a docker hub (docker search)
   pull from a docker hub (docker pull)
   push to a docker hub (docker push)
  - import/export with local filesystem
   load from a local file (docker load)
   save to a local file (docker save)
  - born from scratch
   commit an un-active container to create an image (docker commit)
   build an image with Dockerfile instructions (docker build)
 
  -- management --
  list (docker images)
  remove (docker rmi)

what docker can do with containers in a local container store
  -- creation -- 
   create an un-active container from an image (docker create)
   run from an image with an overwrite command (docker run)
   execute a command (docker exec)

  -- management
   stop an active container with a grace period (docker stop)
   kill an active container (docker kill)
   start an un-active container (docker start)
   restart an active container (docker restart = 
   		docker stop + docker start)
  -
   copy with local filesystem (docker cp)
  -
   attach the console to a container (docker attach)
  -
   commit an un-active container to create an image (docker commit)
  -
   list (docker ps [-a])
   remove (docker rm [-f])
    Note:
  • an image runs a new container with an overwrite command = an image creates a new container + the container starts with an overwrite command
  • a container is created when docker creates from an image or runs from an image with an overwrite command
  • an image is created when docker commits a container or builds from a base image and a Dockerfile
#
#
# image operation
#
#

#### search for an image
docker search image_keyword

#### download an image
docker pull [registry.hub.docker.com/]image_path[:tag] 

#### list images in local drive
docker images [image_path]

#### create new images
1.docker commit -m "submit message" -a "submit user" container_id image_path[:tag]

 $ vi ./Dockerfile
 # This is a comment
 FROM ubuntu:14.04
 MAINTAINER Docker Newbee <newbee docker.com="">
 RUN apt-get -qq update
 RUN apt-get -qqy install ruby ruby-dev
 RUN gem install sinatra
 # put my local web site in myApp folder to /var/www
 ADD myApp /var/www
 # expose httpd port
 EXPOSE 80
 # the command to run
 CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

2.docker build -t="image_path:tag" .  

3.cat ubuntu-14.04-x86_64-minimal.tar.gz  | docker import - ubuntu:14.04

4.docker tag container_id image_path:new_tag

#### upload an image
docker push image_path # all tags

#### save and load an image as local file 
docker save -o ubuntu_14.04.tar ubuntu:14.04

docker load --input ubuntu_14.04.tar
docker load < ubuntu_14.04.tar

#### remove a local image
docker rmi image_path

#
#
# container operation
#
#

#### start and run a container with an image
docker run [-name container_name] ubuntu:14.04 /bin/echo 'Hello world'
docker run -t -i ubuntu:14.04 /bin/bash   ### start a container in interactive mode
docker start ubuntu:14.04

docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
docker ps [-a]     ### list containers, [all, inclusive of un-active containers]
docker logs insane_babbage

#### start and stop container
docker restart
docker stop
docker run -idt ubuntu
docker attach container_name

#### start a shell in a container, detach from it, and re-attach to it
docker exec -it container_name /bin/bash
# use Ctrl-p + Ctrl-q to detach from the container
docker attach container_name

#### import and export container 
docker export container_id > snapshot.tar
cat snapshot.tar | docker import - image_path[:tag]
docker import snapshot_url image_path

#### remove container
docker rm container_name
docker rm $(docker ps -aq)  ## remove all exited containers



References:
1.《Docker —— 從入門到實踐­》Run命令

2.How to use Docker without sudo on Ubuntu
  # grant docker permission to specific user 'foobar'
  > sudo setfacl -m user:foobar:rw /var/run/docker.sock
  > getfacl /var/run/docker.sock
  getfacl: 從絕對路徑名尾部去除"/"字符
  # file: var/run/docker.sock
  # owner: root
  # group: docker
  user::rw-
  user:foobar:rw-
  group::rw-
  mask::rw-
  other::---

3.Prepare docker.service.d/override.conf for the systemd drop-in service
  > sudo systemctl edit docker
  [Service]
  ExecStartPost=/bin/sh -c '/usr/bin/setfacl -m user:foobar:rw /var/run/docker.sock'
  > sudo systemctl daemon-reexec	# re-execute the systemd process
  > sudo systemctl daemon-reload	# reload the systemd manager configuration
  > sudo systemctl restart docker	# stop and start the docker service
    
4.Play With Docker provides an Alpine Linux 3.10 environment with docker and git ready for use
     CPU: Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz with 8 cores
     Memory: 32GB
     Drive: 64GB with 16GB used
     Limit: Use of up to 5 nodes for up to 4 hours per session

沒有留言:

how to install and use Jeddict AI Assistant on NetBeans IDE 23+

Jeddict AI Assistant  為適用於  NetBeans IDE 23 以上版本的插件,能夠連接大語言模型,協助編寫程式碼,大幅提升開發體驗,讓程式撰寫更輕鬆、更智慧。以下簡介其安裝方法及功能。 A.安裝與解除安裝 安裝步驟: ...

總網頁瀏覽量