Docker启动各种服务

2023-12-30 22:34:00

1 启动MySQL

  • 守护方式运行一个容器:
docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 -d mysql
  • 进入容器:
docker exec -it mysql5.7 bash
  • 进入MySQL
mysql -h hostAddress -P port -u user -pPassWD -DDataBase
  • 下载jdbc-driver jar
wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.tar.gz -O /tmp/mysql-connector.tar.gz
wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.28.tar.gz -O /tmp/mysql-connector.tar.gz 

tar -xvzf mysql-connector.tar.gz

2 启动maven,用于编译java程序

 docker run --name hive-compile -it --rm -v "/Users/weiqiang.yu/.m2:/root/.m2" -w "/usr/hive"  \
 -v "/Users/weiqiang.yu/workspace/idea/forked-hive:/usr/hive"  maven:3.8.1-jdk-8 bash

3 容器内启动sshd,用于远程编码和调试

  • 启动容器
podman run --cap-add AUDIT_WRITE --name wechar_build2 -it -d -v /root/.m2:/root/.m2 -v $(pwd):/root/workspace -w /root/workspace --network host --entrypoint bash debian
  • 进入容器启动sshd服务
# attach container
podman exec -it wechar_build2 bash
# install ssh package and generate ssh key
apt update && apt install openssh-server && ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N ''
# generate ssh public key to be used in such as git
ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa

# change the Port in /etc/ssh/sshd_config
echo Port 3368 >> /etc/ssh/sshd_config
# startup sshd
service ssh start
# To debug the sshd, you can run cmd: /usr/sbin/sshd -p3368 -D -d -e

# add your local public key (~/.ssh/id_rsa.pub) to container ~/.ssh/authorized_keys 
# to support ssh login through ssh key
vim ~/.ssh/authorized_keys
  • 配置ssh连接
# ~/.ssh/config
Host dev_container2
    User root
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    ServerAliveInterval 15
    HostName 10.169.5.104
    Port 3368
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand ssh WAN-Jump02 -W %h:%p
  • ssh连接到远程容器
ssh dev_container2

文章来源:https://blog.csdn.net/new_delete_/article/details/121124462
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。