Ubuntu安装docker,并部署API service
Ubuntu 18.04 install docker and deployment API service
First, update existing list of packages:
• sudo apt update
install a few prerequisite packages which let apt use packages over HTTPS:
• sudo apt install apt-transport-https ca-certificates curl software-properties-common
add the GPG key for the official Docker repository to your system:
• curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the Docker repository to APT sources:
• sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable”
update the package database with the Docker packages from the newly added repo:
• sudo apt update
install docker:
• sudo apt-get install docker-ce
Run docker
• sudo systemctl start docker
create dockerfile (the file name must be dockerfile)
FROM python:3
RUN mkdir -p /root/.ssh/ &&
echo “$SSH_KEY” > /root/.ssh/id_rsa &&
chmod -R 600 /root/.ssh/ &&
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
WORKDIR /home/api/testAPI
RUN git config --global http.sslVerify false
RUN git clone “https://username:[email protected]/cvb/dae_cmtool/CILiveDashboard.git”
RUN pip install --no-cache-dir -r “./CILiveDashboard/WebAPI/requirements.txt”
WORKDIR /home/api/testAPI/CILiveDashboard/WebAPI
RUN python3 run.py
Build image from dockerfile
Cd to the dockerfile folder and run below command
• docker build -t testAPI .
Run image
• Docker run -d --restart always imageName
show all container
• docker container ls -all
show all images
• docker images
remove image
• docker rmi -f imageName(imageID)
remove container
• docker rm -f containerID
how to view dictionary in docker image
docker inspect containerid 查看IP地址
sudo nc localhost 56733 使端口可用
docker run -d -p ip:port:dockerport -it imageName
需要确认的是flask的运行host必须是0.0.0.0
docker: Error response from daemon: driver failed programming external connectivity on endpoint brave_knuth (9d854cb5531af29e26fa420eae284c41dfdfa21fc2c2fab4398cace3c2581e19): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 500 -j DNAT --to-destination 172.17.0.3:500 ! -i docker0: iptables: No chain/target/match by that name.
出现以上错误:
- Clear all chains:
sudo iptables -t filter -F
sudo iptables -t filter -X - Then restart Docker Service:
systemctl restart docker
Stop firewall
Is firewalld running on my system?
Run:
sudo firewall-cmd --state
Stop the the firewalld
Again, type:
sudo systemctl stop firewalld