Docker Ubuntu VM 만들기
image 다운로드

 

[root@localhost admin]# docker pull ubuntu:16.04
Trying to pull repository docker.io/library/ubuntu ... 
16.04: Pulling from docker.io/library/ubuntu
fe703b657a32: Pull complete 
f9df1fafd224: Pull complete 
a645a4b887f9: Pull complete 
57db7fe0b522: Pull complete 
Digest: sha256:e9938f45e51d9ff46e2b05a62e0546d0f07489b7f22fbc5288defe760599e38a
Status: Downloaded newer image for docker.io/ubuntu:16.04
docker run
[root@localhost admin]# docker run -dt ubuntu:16.04
WARNING: IPv4 forwarding is disabled. Networking will not work.
5e7a6eadc27aed0e6c3184502e2ae017715b548b51aab857e4ec25a41bbefd44
[root@localhost admin]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5e7a6eadc27a        ubuntu:16.04        "/bin/bash"         10 seconds ago      Up 8 seconds                            gracious_edison
[root@localhost etc]# docker exec -it cocky_einstein /bin/bash
Networking will no work

etc/sysctl.conf

[root@localhost admin]# cd /etc/
[root@localhost etc]# vi sysctl.conf 
[root@localhost etc]# pwd
/etc
[root@localhost etc]# systemctl restart network

이하 vi editor

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_forward=1 # 옆에 추가
ubuntu 이미지 만들기
[root@localhost etc]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
25a922f6ae15        ubuntu:16.04        "/bin/bash"         36 seconds ago      Up 34 seconds                           cocky_einstein

[root@localhost etc]# docker exec -it cocky_einstein /bin/bash
apt-get
root@25a922f6ae15:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [1075 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]        
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]       
Get:7 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [621 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6282 B]
Get:10 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1444 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [1024 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.3 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B]
Get:18 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8807 B]
Fetched 16.4 MB in 6s (2637 kB/s)                                                                                                                                                                                                                                          
Reading package lists... Done
ssh install
root@25a922f6ae15:/# apt-get install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 175 kB of archives.
After this operation, 725 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 net-tools amd64 1.60-26ubuntu1 [175 kB]
Fetched 175 kB in 1s (97.8 kB/s)    
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 4781 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60-26ubuntu1_amd64.deb ...
Unpacking net-tools (1.60-26ubuntu1) ...
Setting up net-tools (1.60-26ubuntu1) ...
root@25a922f6ae15:/# 
root@25a922f6ae15:/# apt-get install openssh-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
root@25a922f6ae15:/# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libgpm2 libpython3.5 vim-common vim-runtime
root@25a922f6ae15:/# cd /etc/ssh
root@25a922f6ae15:/etc/ssh# ls
moduli  ssh_config  ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key  ssh_host_ed25519_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub  ssh_import_id  sshd_config
root@25a922f6ae15:/etc/ssh# vi sshd_config 
PermitRootLogin yes

 

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
root@25a922f6ae15:/etc/ssh# passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@25a922f6ae15:/etc/ssh# service ssh start
 * Starting OpenBSD Secure Shell server sshd                                                                                                                                                                                                                         [ OK ] 
root@25a922f6ae15:/etc/ssh# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3435/sshd       
tcp6       0      0 :::22                   :::*                    LISTEN      3435/sshd       
root@25a922f6ae15:/etc/ssh# exit
docker 이미지 생성
[root@localhost etc]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
25a922f6ae15        ubuntu:16.04        "/bin/bash"         12 minutes ago      Up 12 minutes                           cocky_einstein
[root@localhost etc]# docker commit cocky_einstein ubuntudist:0.1
sha256:32220a3a668ba2c88dbb83471a51c62e4839bece27d7b08057b0b4f03579c39b
[root@localhost etc]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntudist          0.1                 32220a3a668b        17 seconds ago      239 MB
docker.io/nginx     latest              6678c7c2e56c        3 weeks ago         127 MB
docker.io/ubuntu    16.04               77be327e4b63        4 weeks ago         124 MB
docker.io/centos    centos7             5e35e350aded        4 months ago        203 MB
[root@localhost etc]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
25a922f6ae15        ubuntu:16.04        "/bin/bash"         14 minutes ago      Up 14 minutes                           cocky_einstein
[root@localhost etc]# docker run --restart always --name one -dt -p 10001:22 -p 10002:80 -p 10003:443 -p 10004:8080 -p 10005:8090 ubuntudist:0.1
646c193851ab631034f30611dac1af40f68dcb7b907c7d30192a03f480174502
[root@localhost etc]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                                                                                                    NAMES
646c193851ab        ubuntudist:0.1      "/bin/bash"         5 seconds ago       Up 2 seconds        0.0.0.0:10001->22/tcp, 0.0.0.0:10002->80/tcp, 0.0.0.0:10003->443/tcp, 0.0.0.0:10004->8080/tcp, 0.0.0.0:10005->8090/tcp   one

Docker file 생성

상위는 이미지로만 유지되기 때문에 Docker file로 생성해서 유지한다

FROM ubuntu:16.04

MAINTAINER steven;someone@naver.com

RUN apt-get update
RUN apt-get -y install net-tools openssh-server vim
RUN echo 'root:dkssud1!' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config


EXPOSE 22
EXPOSE 80
EXPOSE 443
EXPOSE 8080
EXPOSE 8090

CMD ["/bin/bash"]

ENTRYPOINT service ssh restart && bash

build

$ docker build --tag test:0.2 .

 

command

docker run --restart always --name two -dt -p 10011:22 -p 10012:80 -p 10013:443 -p 10014:8080 -p 10015:8090 test

 

최근 ssh의 config가 변동 된거 같다. 다음과 같이 변경 해야 한다.

FROM ubuntu:18.04

MAINTAINER steven;theyoung2002@naver.com

RUN apt-get update
RUN apt-get -y install net-tools openssh-server vim
RUN echo 'root:dkssud1!' | chpasswd
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22
EXPOSE 80
EXPOSE 443
EXPOSE 8080
EXPOSE 8090

CMD ["/bin/bash"]

ENTRYPOINT service ssh restart && bash

 

windows10 docker에서 bash 접근을 위해서는 다음과 같이 해야 한다.

$ winpty docker exec -it aosp bin/bash
728x90
반응형

'OS' 카테고리의 다른 글

Hyper V Ubuntu File share (samba)  (0) 2020.09.13
virtual host on centos  (0) 2020.03.27
Virtual Box And Vagrant Install on Centos  (0) 2020.03.27
Nexus install on Centos7 with docker  (0) 2020.03.27
Network setup CentOS7 on Virtual Box  (0) 2020.03.27