1. 参考资料

https://blog.csdn.net/qq_27068845/article/details/77015432
https://www.cnblogs.com/sunshine-2015/p/6384471.html
https://www.docker.org.cn/book/docker/docer-save-changes-10.html
https://stackoverflow.com/questions/22907231/how-to-copy-files-from-host-to-docker-container

2. 下载Docker安装程序,确认Hyper-V已经开启

https://docs.docker.com/docker-for-windows/install/

3. 在PowerShell运行docker version确认是否安装成功

Windows 10安装Docker并使用私钥连接AWS EC2
若不成功则重启操作系统后重试

4. 安装Ubuntu

在PowerShell运行docker run -it ubuntu命令,输出以下信息表示安装成功

 Unable to find image 'ubuntu:latest' locally
 latest: Pulling from library/ubuntu
 54ee1f796a1e: Pull complete
 f7bfea53ad12: Pull complete
 46d371e02073: Pull complete
 b66c17bbf772: Pull complete
 Digest: sha256:31dfb10d52ce76c5ca0aa19d10b3e6424b830729e32a89a7c6eee2cda2be67a5
 Status: Downloaded newer image for ubuntu:latest

5. 在PowerShell运行docker images查看image

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4e2eef94cd6b        16 hours ago        73.9MB

6. 在PowerShell启动ubuntu

  • 运行docker run -it --privileged=true -p 10022:22 ubuntu命令进入ubuntu系统
  • 运行lsb_release -a确认系统(注:若lsb_release命令不存在则可使用cat /etc/issue)
    Windows 10安装Docker并使用私钥连接AWS EC2

7. 安装工具

依次运行以下命令

apt-get update
apt-get install vim
apt-get install openssh-server

8. 创建私钥,添加内容后修改权限

Windows 10安装Docker并使用私钥连接AWS EC2
运行ssh -i ~/aws/key {ec2.user}@{ec2.id.address}连接EC2

9. 保存image

  • 在PowerShell运行docker ps -l查看Container
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
2e48d1d6cd44        2cdf64bb985d        "/bin/bash"         21 minutes ago      Up 21 minutes       0.0.0.0:10022->22/tcp   ecstatic_nash
  • 在PowerShell运行docker commit {CONTAINER ID} {image.name}(例如docker commit 2e48d1d6cd44 test/ubuntu)
  • 在PowerShell运行docker images查看image
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
test/ubuntu         latest              38416deebfd4        52 seconds ago      263MB
ubuntu              latest              4e2eef94cd6b        16 hours ago        73.9MB

10. 关闭docker进程

  • 关闭特定进程:在PowerShell运行docker kill {CONTAINER ID}
  • 关闭所有:在PowerShell运行docker stop $(docker ps -a -q)命令

11. 重启已经关闭的container并打开bash

  • docker container ls -a找到container id
  • docker start {CONTAINER ID}启动
  • docker exec -it {CONTAINER ID} bash打开容器终端

12. 容器与主机文件互传

  • 启动容器(例如docker run -it --privileged=true -p 10022:22 test/ubuntu)
  • 查看正在运行的container id docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
7bc4886a6824        test/ubuntu         "/bin/bash"         13 seconds ago      Up 12 seconds       0.0.0.0:10022->22/tcp   mystifying_panini
  • 主机->容器 docker cp {source.file.path} {CONTAINER ID}:{target.file.path}(例如docker cp .\key 7bc4886a6824:/tmp)
  • 容器->主机 docker cp {CONTAINER ID}:{source.file.path} {target.file.path}(例如docker cp 7bc4886a6824:/tmp/key ~\Desktop)

相关文章:

  • 2021-12-19
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-04-16
  • 2021-05-17
  • 2022-12-23
  • 2021-04-01
猜你喜欢
  • 2021-11-28
  • 2021-06-07
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案