Docker现在已经支持在windows下安装,不过我用的是阿里云的ubuntu系统,所以下面的安装使用都是基于ubuntu系统的,centos也差不多,只不过是用yum来安装,ubuntu使用apt安装

安装

  1. 登陆自己的linux服务器,设置apt的源
vim /etc/apt/sources.list

设置为阿里的镜像源

deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main

deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main

deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic universe
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates universe

deb http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security main
deb http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security universe
  1. 设置docker镜像源
vim /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
  1. 更新镜像源以及安装依赖软件
sudo apt-get update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
  1. 添加秘钥安装docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-get install docker-ce
  1. 查看版本
docker version

能显示说明安装成功

运行第一个例子

  1. 拉取镜像,是从docker官方仓库拉取,你也可以指定地址如网易的仓库
docker pull hello-world
  1. 查看镜像
docker images

hello-world                   latest              fce289e99eb9        6 months ago        1.84kB

我们可以看到刚才拉到本地的镜像

  1. 启动镜像
docker run hello-world

出现这样的信息,说明启动成功

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

基础命令

  1. 当前的docker应用
docker ps
  1. 当前运行的容器
docker container ls

和docker ps 一样

  1. 运行镜像,启动镜像后悔生成一个容器
docker run 镜像名:tag     #tag 可选
  1. 停止容器,也指停止docker应用
docker stop 容器id
  1. 删除容器
docker rm -f 容器id
  1. 删除镜像,必须先停止使用该镜像的容器
docker rmi -f 镜像名:tag
  1. 从远程仓库拉镜像
docker pull 镜像名:tag     #如果是私有仓库,需要用户名密码验证。默认官方公共仓库
  1. 显示本地的所有镜像
docker images

基本有了这些命令,你就可以开始玩docker了,下节课,开始使用docker运行一个简单的java应用,以及学习docker镜像的制作。

欢迎关注我的公中号:mike啥都想搞,一起交流学习

mike啥都想搞


Mike晓
95 声望18 粉丝