Docker、Laradock命令

Docker常用命令

#使用docker:
systemctl start/stop/restart/status docker
sudo service docker start/stop/restart/status
systemctl enable docker        #开机启动
sudo systemctl daemon-reload   #守护进程重启 

#镜像
docker images / docker image ls #列出本地镜像
docker rmi training/sinatra #删除(在删除镜像之前要先用 docker rm 删掉依赖于这个镜像的所有容器)
docker run -t -i ubuntu:14.04 /bin/bash #
【docker run -ti --name myubuntu -d ubuntu】{创建一个名为myubuntu的容器:ubuntu为REPOSITORY不加tag}
docker commit -m "Added json gem" -a "Docker Newbee" 0b2616b0e5a8 ouruser/sinatra:v2 #更新镜像 
【其中,-m 来指定提交的说明信息,跟我们使用的版本控制工具一样;-a 可以指定更新的用户信息;之后是用来创建镜像的容器的 ID;最后指定目标镜像的仓库名和 tag 信息。创建成功后会返回这个镜像的 ID 信息。】
docker tag 5db5f8471261 ouruser/sinatra:devel #修改标签
docker build ${dockerfile_dir} #Dockerfile 构建
docker save -o ubuntu_14.04.tar ubuntu:14.04 #保存
docker load --input ubuntu_14.04.tar #导入

#容器
docker ps #查看容器信息
docker rm #删掉容器(-f 删除运行中)
docker inspect #查看指定容器详细信息(可获取ip,pid等信息)
docker logs insane_babbage #查看容器log
docker port CONTAINER [PRIVATE_PORT[/PROTO]] #查看端口映射
docker start|stop|restart insane_babbage #启动终止重启
docker attach insane_babbage #进入后台运行的容器 -d(推荐nsenter)| 输出容器内的信息
docker export 7691a814370e > ubuntu.tar #导出快照
cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0 #导入快照
## docker hub 
docker search #搜索镜像
docker pull #下载
docker login #登录
docker push #推送(需登录)

#部署docker项目
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-   //将服务器项目部署到docker容器中
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
docker cp实例
将主机/www/runoob目录拷贝到容器96f7f14e99ab的/www目录下。

docker cp /www/runoob 96f7f14e99ab:/www/
将主机/www/runoob目录拷贝到容器96f7f14e99ab中,目录重命名为www。

docker cp /www/runoob 96f7f14e99ab:/www
将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。

docker cp  96f7f14e99ab:/www /tmp/

Docker不常用命令

#docker 容器(服务)重命名
docker rename 原容器名  新容器名

Docker官方演示用到的命令 

##第一部分 方向
## List Docker CLI commands
docker
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

docker run hello-world  ## Execute Docker image
docker image ls  ## List Docker images

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq
注:docker ps命令等价于docker container ls命令。

##第二部分 容器 container
docker build -t friendlyhello .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello  # Run "friendlyhello" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello         # Same thing, but in detached mode
docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running
docker container stop            # Gracefully stop the specified container
docker container kill          # Force shutdown of the specified container
docker container rm         # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers
docker image ls -a                             # List all images on this machine
docker image rm             # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag  username/repository:tag  # Tag  for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry


##第三部分 服务  service
docker stack ls                                            # List stacks or apps
docker stack deploy -c    # Run the specified Compose file
docker service ls                 # List running services associated with an app
docker service ps                   # List tasks associated with an app
docker inspect                    # Inspect task or container
docker container ls -q                                      # List container IDs
docker stack rm                              # Tear down an application
docker swarm leave --force      # Take down a single node swarm from the manager

注意:

此外,还可以利用 ADD 命令复制本地文件到镜像;用 EXPOSE 命令来向外部开放端口;用 CMD 命令来描述容器启动后运行的程序等。例如

# 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"]

Laradock 是什么?

Laradock是一个利用Docker实现的WEB环境配置工具,集成了大量WEB开发领域会用到的软件,如Redis,Mysql,MongoDB等.为PHP/Laravel开发和部署提供了极大的便利,前面有讲安装Laradock

docker-compose 两种安装 :Link

1、

非root身份
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

2、

Docker、Laradock命令_第1张图片

docker-compose:

  build              Build or rebuild services
  bundle             Generate a Docker bundle from the Compose file
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information

Laradock官方地址:Laradock官方地址 

 

你可能感兴趣的:(docker,Laradock)