Docker Image Build
빌드할 어플리케이션 준비
import socket
with socket.socket() as s:
s.bind(("0.0.0.0", 12345))
s.listen()
print("server is started")
conn, addr = s.accept()
with conn:
print("Connected by", addr)
while True:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
python3 test_server.py
---
nc 127.0.0.1 12345
도커 파일 생성
mkdir my_first_project
mv test_server.py ./my_first_project/
cd my_first_project/
gedit dockerfile
dockerfile
FROM python:3.7
RUN mkdir /echo
COPY test_server.py /echo
CMD ["python", "/echo/test_server.py"]
빌드 후 테스트
ls
dockerfile test_server.py
sudo docker build -t ehco_test .
sudo docker images
sudo docker run -t -p 12345:12345 --name et --rm echo_test