1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Dockerfileを利用したSSHサーバ構築

Last updated at Posted at 2022-08-02

Dockerfileを利用したSSHサーバ構築

Dockerfile他の準備

$ pwd
/home/masa/docker
$ 
$ ls -a
.   Dockerfile         containerStart.sh  test1_t1.tar
..  containerSetup.sh  init.sh            webtest_img.tar
$ 
$ cat Dockerfile 
FROM ubuntu:latest
RUN echo "now building..."
RUN apt-get update
RUN apt-get install -y openssh-server
RUN useradd -m sshcon
RUN echo sshcon:'sshssh' | /usr/sbin/chpasswd
ADD ./init.sh /root/init.sh
RUN chmod 777 /root/init.sh
RUN echo "finish"
$ 
$ cat init.sh 
#!/bin/bash
/etc/init.d/ssh start

Dockerファイルを実行してイメージ作成

$ sudo docker image build -t taka/sshhost:1.3 .
[sudo] masa のパスワード: 
Sending build context to Docker daemon  477.2MB
Step 1/3 : FROM ubuntu
(cut)
 ---> 669d15c3f5b0
Successfully built ae850e39625c

$ docker image ls
REPOSITORY     TAG       IMAGE ID       CREATED          SIZE
taka/sshhost   1.3       669d15c3f5b0   36 minutes ago   224MB
(cut)
ubuntu         latest    27941809078c   8 weeks ago      77.8MB

Docker container の作成

shを作成して実行させる
同時実行は検証中(T_T)

$ cat containerSetup.sh 
#!/bin/bash
docker run -it --name "taka1" -h Taka1 --net=grpA --ip=192.168.100.15 669d15c3f5b0 /bin/bash
#docker run -it --name "taka2" -h Taka2 --net=grpA --ip=192.168.100.16 669d15c3f5b0 /bin/bash
⇑未使用分はコメントアウトしておく

Docker container の起動

shを作成して実行させる

$ cat containerStart.sh 
#!/bin/bash
docker container start taka1
docker container exec -it taka1 /root/init.sh
docker container start taka2
docker container exec -it taka2 /root/init.sh
docker container ls
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?