docker安装+使用总结

一.Docker安装

参考链接(官网):https://docs.docker.com/install/linux/docker-ce/centos/#install-docker-ce-1

此处以CentOS下安装Docker为例:

Installusing the repository

Before you install Docker CE for the first time on a new hostmachine, you need to set up the Docker repository. Afterward, you can installand update Docker from the repository.

SET UP THEREPOSITORY

1.      Install required packages. yum-utils provides the yum-config-manager utility, anddevice-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.

2.  $ sudo yum install -y yum-utils \
3.    device-mapper-persistent-data \
4.    lvm2

5.      Use the following command to set up the stable repository. You always need the stablerepository,even if you want to install builds from the edge or test repositories as well.

6.  $ sudo yum-config-manager \
7.      --add-repo\
8.      https://download.docker.com/linux/centos/docker-ce.repo

9.      Optional: Enable the edge and test repositories. These repositories areincluded in thedocker.repo file above but are disabled by default. You can enable themalongside the stable repository.

10.  $ sudo yum-config-manager --enable docker-ce-edge
11.  $ sudo yum-config-manager --enable docker-ce-test

You can disable the edge or test repository by running the yum-config-manager command with the --disable flag. To re-enable it, use the --enable flag. The following command disables theedge repository.

$ sudo yum-config-manager --disable docker-ce-edge

Note: Starting with Docker17.06, stable releases are also pushed to the edge and testrepositories.

Learn about stable and edge builds.

INSTALL DOCKER CE

1.      Install the latestversion of Docker CE,or go to the next step to install a specific version:

$ sudo yum install docker-ce

2.      Start Docker.

$ sudo systemctl start docker

3.      Verify that docker is installed correctly by running the hello-world image.

$ sudo docker run hello-world

二.更改Docker镜像默认存储路径

  默认情况下,docker镜像的默认存储路径是/var/lib/docker,这相当于直接挂载系统目录下,而一般在搭系统时,这个区都不会太大,所以如果长期使用docker开发应用,就需要把默认的路径更改到/home路径下(这个区一般会分得比较多)

  命令行:

  vi/usr/lib/systemd/system/docker.service

  在文本内容ExecStart=/usr/bin/dockerd 后面添加如下内容:

  --graph  <yourpath>使得变成:

  ExecStart=/usr/bin/dockerd \

                       --graph <your path>

  然后重新加载配置文件

  systemctldaemon-reload

  最后重启即可

  systemctlrestart docker

注:更改过后,之后卸载docker并删除所有镜像和容器的目录,就要rm -rf <your path>

三.常用命令总结

#构建镜像(当前目录下需要有Dockerfile文件)

dockerbuild -t showdoc ./

#查看镜像

docker  images

#删除镜像

dockerrmi  镜像名称

#查看容器(默认查看运行中的容器)

docker  ps

#查看所有容器

docker  ps  -a

#删除容器(删除前需要确保容器停止运行)

docker  rm   容器名

 

#运行一个web应用

#前面我们运行的容器并没有一些什么特别的用处。

#接下来让我们尝试使用 docker 构建一个 web 应用程序。

#参数说明:

#-d:让容器在后台运行。

#-P:将容器内部使用的网络端口映射到我们使用的主机上。

#--name指定容器名称

 

dockerrun -d --name showdoc -p 4999:80 showdoc

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值