1.Ubuntu安装docker准备篇

2022-09-11 13:01:06 浏览数 (1)

Linux安装docker

首先用vagrant创建一个新的虚拟机。这里不在过多说明,有需要请移步这篇文章<<Mac上下载安装Vagrant、配置打包属于自己的开发环境(使用Homestead后续也会更新出来)>> 这里简单粗略的贴一下创建过程

代码语言:javascript复制
zhengniu@Mac vagrant % mkdir docker2 && cd docker2  # 创建一个新的文件夹并且进入文件夹
zhengniu@Mac docker2 % vagrant box list  #列出当前所有Box              
docker_ubuntu (virtualbox, 0)
ub2020        (virtualbox, 0)
ubuntu1606    (virtualbox, 0)
zhengniu@Mac docker2 % vagrant box add docker2 ../box/ubuntu1606.box #添加一个名称为docker2的Box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'docker2' (v0) for provider:
    box: Unpacking necessary files from: file:///Users/zhengniu/Downloads/study/vagrant/box/ubuntu1606.box
==> box: Successfully added box 'docker2' (v0) for 'virtualbox'!        
zhengniu@Mac docker2 % vagrant init docker2  #初始化一个新VM 即虚拟机
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
zhengniu@Mac docker2 % ls #生成一个配置文件
Vagrantfile
zhengniu@Mac docker2 % sudo vi Vagrantfile #修改配置文件
Password:  

找到这个行,把注释去掉 config.vm.network "private_network", ip: "192.168.33.12" #打开配置设置静态IP (和主机保持在同一网段)

代码语言:javascript复制
zhengniu@Mac docker2 % vagrant up # 启动虚拟机
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'docker2'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: docker2_default_1599362376454_99012
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 5.1.38
    default: VirtualBox Version: 6.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/zhengniu/Downloads/study/vagrant/docker2   #与主机默认的共享目录
 
    zhengniu@Mac docker2 % vagrant ssh # 进入创建的虚拟机
    Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-161-generic x86_64)
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    0 packages can be updated.
    0 updates are security updates.
    New release '18.04.5 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.
    vagrant@ubuntu-xenial:~$

0 人点赞