How to migration exist service as container
如果手上有既有的服務跑在一台Linux的機器上,該怎麼打包docker images
Step1: Analysis how many serice running in exsit sever
Example:
I have a “TPS/PXE server running service” are below
- httpd (TCP/80)
- samba (TCP/139)
- tpserver/java (TCP/9000; TCP/9005)
- tftp/xinetd (UCP/69)
- nfs/portmap (TCP/111; UDP/111; TCP/2049; UDP/2049; TCP/20048; UDP/20048)
Step2: Container each service as microservice
Buildup images by Dockerfile
https://github.com/jerryk2/tps/tree/master/Dockerfile
Step3: Using docker-compose to run all of tps container images
https://docs.docker.com/compose/
Docker Compose is a tool for defining and running multi-container Docker applications.
Docker compose file
https://github.com/jerryk2/tps/blob/master/docker-compose.yml
Perform command:
/usr/bin/docker-compose -f /opt/tps/docker-compose.yml up -d
Step 4: Build-up high availability service by OS cluster or kubernets cluster
$ cat /etc/systemd/system/tps.service
[Unit]
Description=tps
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStartPre=/usr/bin/docker-compose -f /opt/tps/docker-compose.yml down -v
ExecStartPre=/usr/bin/docker-compose -f /opt/tps/docker-compose.yml rm -v
ExecStartPre=-/bin/bash -c ‘docker rm -v $(docker ps -aq | gre tps)’
ExecStart=/usr/bin/docker-compose -f /opt/tps/docker-compose.yml up
ExecStop=/usr/bin/docker-compose -f /opt/tps/docker-compose.yml down -v
[Install]
WantedBy=multi-user.target
$ systemctl daemon-reload
$ systemctl status tps.service