阅读量: 次  文章字数: 272字  阅读时长: 1分钟

Docker Issues in Development

Common Docker Operations and Commands

Create Docker Image for Python Projects

  1. Configure Dependencies
1
2
3
pip freeze > requirements.txt
touch Dockerfile
vim Dockerfile
  1. Create and Edit Dockerfile
1
2
3
4
5
6
FROM python:3.10.12
ADD . /code
WORKDIR /code
# Install Dependencies
RUN pip install -r requirements.txt
CMD ["python", "/hello.py"]
  1. Build Docker Image & run
1
2
3
docker build -t demo .
docker run -it demo
docker run -itd --name demo -p 5000:5000 demo

Pull or Push Docker Images

Docker Hub

login to Docker Hub;

1
2
3
4
5
6
7
8
9
[root@localhost ~]
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username:
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Edit Tag

  • Push Command docker push docker_username/REPOSITORY:TAG
  • We need to edit the tag and repository name:
1
2
3
4
5
6
7
8
9
[root@localhost ~]# docker images 
REPOSITORY TAG IMAGE ID CREATED SIZE
demo latest 1e5f6711d527 3 days ago 178MB
[root@localhost ~]# docker tag demo:latest ***/demo:v1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
demo latest 1e5f6711d527 3 days ago 178MB
***/demo v1 1e5f6711d527 3 days ago 178MB
[root@localhost ~]#

Push

1
2
3
4
5
6
7
8
[root@localhost ~]# docker push ***/demo:v1
The push refers to repository [docker.io/***/demo:v1]
833a0t6a6ff9: Pushed
10bfe4y2500e: Pushed
d43sfdd7d594: Mounted from library/nginx
c2adabsadfed: Mounted from library/nginx
v1: digest: sha256:67dcdae5578c0374019bdc899731543cfd7c48fe5780e84233a258f2bf7d2ceda size: 1155
[root@localhost ~]#

Pull

1
2
3
4
5
[root@localhost ~]# docker pull ***/demo:v1
v1: Pulling from ***/demo:v1
Digest: sha256:67dcdae5578c0374019bdc899731543cfd7c48fe5780e84233a258f2bf7d2ceda
Status: Downloaded newer image for ***/demo:v1
docker.io/llxxyy/nginx-io:v1

Comments

2024-08-02