docker-compose部署一个可远程连接的容器

 

一个例子

version: '2.0'
services:

  m3-test:
    image: ubuntu:16.04
    container_name: m3-test
    tty: true
    privileged: true
    entrypoint: ["sh"]
    restart: always
    ports:
      - "8100:22"
    volumes:
      - ./script:/mnt/script
    working_dir: /mnt/script

 

进入容器执行下面命令
apt-get install openssh-server -y
成功安装后,vim /etc/ssh/sshd_config,修改下面两个配置
PermitRootLogin yes  
UsePAM no
保存退出后启动ssh服务,service ssh start
passwd设置密码
 
然后可以提交容器为镜像:docker commit 容器ID ubuntu-ssh

 

修改docker-compose中的镜像名

version: '3'
services:
  certbot:
    container_name: ubuntu-ssh
    image: ubuntu-ssh

    tty: true
    privileged: true
    entrypoint: ["/usr/sbin/sshd", "-D"]    

    ports:
      - "8100:22"
    volumes:
      - ./letsencrypt:/etc/letsencrypt
      - ./certbot-alydns:/var/lib/alydns
    working_dir: /var/lib/alydns

 

posted @ 2022-02-24 17:16  坚强的小蚂蚁  阅读(356)  评论(0编辑  收藏  举报