The following is the code for building an ssh service based on the golang image in docker. The specific content is as follows: # golang:latest image FROM ee23292e2826 # Author MAINTAINER [email protected] # Add Golang environment variable ENV GOPROXY https://goproxy.cn,direct ENV GO111MODULE on # Configure apt-get source ADD sources.list /etc/apt/ # Update apt-get source Install ssh service Modify root password Configure ssh service Allow root remote login Write "Enable ssh service Write address information to /root/ip.txt and tail -f" to /root/ip.sh Give ip.sh execution permission RUN apt-get update \ && apt-get -y install ssh \ && echo "root:1" | chpasswd \ && echo "PermitRootLogin yes" >> /etc/ssh/sshd_config \ && echo "service ssh start && ip addr | grep global > /root/ip.txt && tail -f /root/ip.txt" > /root/ip.sh \ && chmod +x /root/ip.sh # Execute ENTRYPOINT ["sh","-l"] at startup CMD ["/root/ip.sh"]
PS: Docker based on sshd and golang environment under CentOS 1. Dockerfile #Inherit centos7 image FROM centos:centos7 MAINTAINER tpythoner [email protected]" #yum install sshd service #RUN yum install -y openssh openssh-server openssh-clients RUN yum install -y openssh-server #Create sshd RUN mkdir /var/run/sshd RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key #Set the root password and add the tpythoner user RUN /bin/echo 'root:mypwd' |chpasswd RUN useradd tpythoner RUN /bin/echo 'tpythoner:mypwd' |chpasswd #Cancel pam restriction RUN /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g' /etc/pam.d/sshd RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" > /etc/default/local #Install golang #RUN yum install -y wget #RUN wget http://golangtc.com/static/go/go1.4.2.linux-amd64.tar.gz #RUN tar zxvf go1.4.2.linux-amd64.tar.gz -C /usr/local/ ADD go1.4.2.linux-amd64.tar.gz /root ADD golang.conf /root/golang.conf RUN mv /root/go /usr/local/ #RUN echo "export GOROOT=/usr/local/go" >> /etc/profile #RUN echo "export GOBIN=$GOROOT/bin" >> /etc/profile #RUN echo "export PATH=$PATH:$GOBIN" >> /etc/profile #RUN echo "export GOPATH=/home/golang" >> /etc/profile RUN cat /root/golang.conf >> /etc/profile RUN echo "source /etc/profile" >> /root/.bashrc RUN mkdir -p /home/golang # Development port EXPOSE 22 EXPOSE 80 #Start sshd service CMD /usr/sbin/sshd -D 2. golang.conf export GOROOT=/usr/local/go export GOBIN=$GOROOT/bin export PATH=$PATH:$GOBIN export GOPATH=/home/golang 3. Download go1.4.2.linux-amd64.tar.gz
4. Create new docker images
5. Run the image to generate the container docker run -d -p 2222:22 -p 80:80 centos:go_sshd #If you encounter WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! echo '' >> ~/.ssh/known_hosts 6. Connect to the go_sshd container
This is the end of this article about building ssh service with docker based on golang image. For more information about building ssh service with docker, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Example of Form action and onSubmit
>>: Detailed explanation of the sticky position attribute in CSS
1. What is an index? An index is a data structure...
Table of contents Preface Modifiers of v-model: l...
MySQL replication detailed explanation and simple...
<br />Original article: http://www.alistapar...
As we all know, there are two types of images in c...
The functions of the three attributes flex-grow, ...
Preface Mobile devices have higher requirements f...
01. Infinity Font Download 02. Banda Font Download...
As one of the most commonly used and important ut...
First: Installation of MySQL Download the MySQL s...
Table of contents Overview Code Implementation Su...
Because I need to use Ubuntu+Python 3.6 version t...
If we introduce the nesting rules of basic HTML w...
When I first used docker, I didn't use docker...
How to uninstall Mysql perfectly? Follow the step...