I am new to docker and trying to steup my django project using docker first time.
I am following https://docs.docker.com/compose/django/
Below are the files and their conents that am using.
am using Ubuntu 16
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
docker-compose.yml
version: '3'
services:
db:
image: mysql
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
requirements.txt
Django>=2.0,<3.0
psycopg2>=2.7,<3.0
I ran the below command
docker-compose run web django-admin startproject composeexample .
I have doubt in the below output:
.....:~/docker_practice$ docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_practice_web latest be61fbfc4d9e 49 seconds ago 960MB
<none> <none> e73f8a4d68de 52 seconds ago 960MB
<none> <none> 7b597f9f4615 About a minute ago 918MB
<none> <none> 0eaf59a89be4 About a minute ago 918MB
<none> <none> cc42d26c3cfb About a minute ago 918MB
<none> <none> ae64e2080658 About a minute ago 918MB
python 3 02d2bb146b3b 11 days ago 918MB
mysql latest b8fd9553f1f0 12 days ago 445MB
.......:~/docker_practice$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_practice_web latest be61fbfc4d9e 52 seconds ago 960MB
python 3 02d2bb146b3b 11 days ago 918MB
mysql latest b8fd9553f1f0 12 days ago 445MB
When I run "docker images -a" It display 5 images with name as
What this images are?
where does it coming from ?
the command docker images -a will show you also intermediate images, which is hidden in default using docker images
see this
Related
Hi after changing files names and removing and reinstalling docker (I had to choose another package)
I get a problem with removing image from older installation
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
(nothing)
docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
linuxserver/bookstack latest de5fa1566aec 10 days ago 262MB
my attempts:
docker image rm linuxserver/bookstack
Error: No such image: linuxserver/bookstack
docker image rm linuxserver/bookstack:latest
Error: No such image: linuxserver/bookstack:latest
docker image rm de5fa1566aec
Error: No such image: de5fa1566aec
docker rmi -f linuxserver/bookstack:latest
Error: No such image: linuxserver/bookstack:latest
docker rmi -f linuxserver/bookstack
Error: No such image: linuxserver/bookstack
docker rmi -f de5fa1566aec
Error: No such image: de5fa1566aec
another idea:
docker system prune
WARNING! This will remove:
all stopped containers
all networks not used by at least one container
all dangling images
all dangling build cache
Are you sure you want to continue? [y/N] y Total reclaimed space: 0B
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
linuxserver/bookstack latest de5fa1566aec 10 days ago 262MB
overwriting
docker image import bookstack.docker
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 47f974b4ca36 11 seconds ago 278MB
linuxserver/bookstack latest de5fa1566aec 11 days ago 262MB
my last hit
docker rmi $(docker images -a -q)
Error: No such image: de5fa1566aec
Slava Kuravsky solution
docker tag busybox:latest linuxserver/bookstack:latest
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 47f9* 2 days ago 278MB
linuxserver/bookstack latest de5f* 13 days ago 262MB
busybox latest ff4a* 2 weeks ago 1.24MB
linuxserver/bookstack latest ff4a* 2 weeks ago 1.24MB
docker system prune -f
Deleted Images:
deleted: sha256:47f9****
deleted: sha256:29ef****
docker rmi -f linuxserver/bookstack:latest
Untagged: linuxserver/bookstack:latest
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
linuxserver/bookstack latest de5fa*** 13 days ago 262MB
busybox latest ff4a8*** 2 weeks ago 1.24MB
Still don't work :(
Try to pull this image again and override the broken reference: docker pull linuxserver/bookstack:latest
I have a docker compose file for my nodejs application. I need to hide the connection string and take it out from docker secret and assign it to the env variable to initiate the database connection. But the env being assigned seems to be a path rather than the desired secret value. Please guide me. Thank you.
here is my docker-compose.yml
version: "3.1"
services:
web_server:
image: "nginxdemos/hello"
secrets:
- secret_value
environment:
NODE_ENV: production
SECRET_ENV: /run/secrets/secret_value
ports:
- "80:5001"
secrets:
secret_value:
external: true
My index.js
router.get('/', function(req, res, next) {
res.send('Server is running ' + process.env.SECRET_ENV);
});
Commands:
nguyenthanh#MacBook-Pro-cua-Nguyen NextZone % docker secret ls
ID NAME DRIVER CREATED UPDATED
tw9c2q55u511s5xt0n46s9cam db_host 2 days ago 2 days ago
plslnygpghdh1jljz8iytzjq4 my_external_secret 2 days ago 2 days ago
z8jalp982098swxy4abycl6so secret_value 2 hours ago 2 hours ago
nguyenthanh#MacBook-Pro-cua-Nguyen NextZone % docker stack deploy --compose-file=docker-compose.yml secret_test
Creating service secret_test_web_server
nguyenthanh#MacBook-Pro-cua-Nguyen NextZone % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9635bd581a80 nginxdemos/hello:latest "/docker-entrypoint.…" 11 seconds ago Up 11 seconds 80/tcp secret_test_web_server.1.b6wg1s5usb6euaw79unpbh9f7
nguyenthanh#MacBook-Pro-cua-Nguyen NextZone % docker exec 9635bd581a80 cat /run/secrets/secret_value
sec180499
nguyenthanh#MacBook-Pro-cua-Nguyen NextZone % docker exec 9635bd581a80 cat printenv
cat: can't open 'printenv': No such file or directory
nguyenthanh#MacBook-Pro-cua-Nguyen NextZone % docker exec 9635bd581a80 printenv
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=9635bd581a80
NODE_ENV=production
SECRET_ENV=/run/secrets/secret_value
NGINX_VERSION=1.21.6
NJS_VERSION=0.7.2
PKG_RELEASE=1
HOME=/root
I'm expecting my env to look like this SECRET_ENV=sec180499
Recently i tried to install Gitlab on Ubuntu machine using docker and docker-compose. This was only done for testing so i can later install it on other machine.
However, i have a problem with removing/deleting gitlab containers.
I tried docker-compose down and killing all processes related to gitlab containers but they keep restarting even if i somehow manage to delete images.
This is my docker-compose.yml file
version: "3.6"
services:
gitlab:
image: gitlab/gitlab-ee:latest
ports:
- "2222:22"
- "8080:80"
- "8081:443"
volumes:
- $GITLAB_HOME/data:/var/opt/gitlab
- $GITLAB_HOME/logs:/var/log/gitlab
- $GITLAB_HOME/config:/etc/gitlab
shm_size: '256m'
environment:
GITLAB_OMNIBUS_CONFIG: "from_file('/omnibus_config.rb')"
configs:
- source: gitlab
target: /omnibus_config.rb
secrets:
- gitlab_root_password
gitlab-runner:
image: gitlab/gitlab-runner:alpine
deploy:
mode: replicated
replicas: 4
configs:
gitlab:
file: ./gitlab.rb
secrets:
gitlab_root_password:
file: ./root_password.txt
Some of the commands i tried to kill processes:
kill -9 $(ps aux | grep gitlab | awk '{print $2}')
docker rm -f $(docker ps -aqf name="gitlab") && docker rmi --force $(docker images | grep gitlab | awk '{print $3}')
I also tried to update containers with no restart policy:
docker update --restart=no container-id
But nothing of this seems to work.
This is docker ps response:
591e43a3a8f8 gitlab/gitlab-ee:latest "/assets/wrapper" 4 minutes ago Up 4 minutes (health: starting) 22/tcp, 80/tcp, 443/tcp mystack_gitlab.1.0r77ff84c9iksmdg6apakq9yr
6f0887a8c4b1 gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.3.639u8ht9vt01r08fegclfyrr8
73febb9bb8ce gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.4.m1z1ntoewtf3ipa6hap01mn0n
53f63187dae4 gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.2.9vo9pojtwveyaqo166ndp1wja
0bc954c9b761 gitlab/gitlab-runner:alpine "/usr/bin/dumb-init …" 16 minutes ago Up 16 minutes mystack_gitlab-runner.1.pq0njz94v272s8if3iypvtdqo
Any ideas of what i should be looking for?
I found the solution. Problem was that i didn't use
docker-compose up -d
to start my containers. Instead i used
docker stack deploy --compose-file docker-compose.yml mystack
as it is written in documentation.
Since i didn't know much about docker stack, i did a quick internet search.
This is the article that i found:
https://vsupalov.com/difference-docker-compose-and-docker-stack/
The Difference Docker stack is ignoring “build” instructions. You
can’t build new images using the stack commands. It need pre-built
images to exist. So docker-compose is better suited for development
scenarios.
There are also parts of the compose-file specification which are
ignored by docker-compose or the stack commands.
As i understand, the problem is that stack only uses pre-built images and ignores some of the docker-compose commands such as restart policy.
That's why
docker update --restart=no container-id
didn't work.
I still don't understand why killing all the processes and removing containers/images didn't work. I guess there must be some parent process that i didn't found.
I'm trying to set up a lab using docker containers with base image centos7 and docker-compose.
Here is my docker-compose.yaml file
version: "3"
services:
base:
image: centos_base
build:
context: base
master:
links:
- base
build:
context: master
image: centos_master
container_name: master01
hostname: master01
volumes:
- ansible_vol:/var/ans
networks:
- net
host01:
links:
- base
- master
build:
context: host
image: centos_host
container_name: host01
hostname: host01
command: ["/var/run.sh"]
volumes:
- ansible_vol:/var/ans
networks:
- net
networks:
net:
volumes:
ansible_vol:
My Docker files are as below
Base Image docker file:
# For centos7.0
FROM centos:7
RUN yum install -y net-tools man vim initscripts openssh-server
RUN echo "12345" | passwd root --stdin
RUN mkdir /root/.ssh
Master Dockerfile :
FROM centos_base:latest
# install ansible package
RUN yum install -y epel-release
RUN yum install -y ansible openssh-clients
RUN mkdir /var/ans
# change working directory
WORKDIR /var/ans
RUN ssh-keygen -t rsa -N 12345 -C "master key" -f master_key
CMD /usr/sbin/sshd -D
Host Image Dockerfile:
FROM centos_base:latest
RUN mkdir /var/ans
COPY run.sh /var/
RUN chmod 755 /var/run.sh
My run.sh file:
#!/bin/bash
cat /var/ans/master_key.pub >> /root/.ssh/authorized_keys
# start SSH server
/usr/sbin/sshd -D
My Problems are:
If I run docker-compose up -d --build, I see no containers coming up. they all getting created but exiting.
Successfully tagged centos_host:latest
Creating working_base_1 ... done
Creating master01 ... done
Creating host01 ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
433baf2dd0d8 centos_host "/var/run.sh" 12 minutes ago Exited (1) 12 minutes ago host01
a2a57e480635 centos_master "/bin/sh -c '/usr/sb…" 13 minutes ago Exited (1) 12 minutes ago master01
a4acf6fb3e7b centos_base "/bin/bash" 13 minutes ago Exited (0) 13 minutes ago working_base_1
ssh keys generated in 'centos_master' image are not available in centos_host container, even though I have added a volume mapping 'ansible_vol:/var/ans' in docker-compose file
My intention is these ssh key files generated in master should be available in host containers ,therefore the run.sh script can copy them to authorized_keys section of host containers.
Any help is greatly appreciated.
Try to put in base/Dockerfile :
RUN echo "12345" | passwd root --stdin; \
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -b 4096 -t rsa
and rerun docker-compose build
/etc/ssh/ssh_host_rsa_key is a key used by sshd (ssh daemon), so that containers can be started properly.
The key you generated and copied into authorized_keys will be used to allow ssh client to connect to container via ssh.
Try to use external: false, to not attempt the container to create it and override the previous data at creation
version: "3"
services:
base:
image: centos_base
build:
context: base
master:
links:
- base
build:
context: master
image: centos_master
container_name: master01
hostname: master01
volumes:
- ansible_vol:/var/ans
networks:
- net
host01:
links:
- base
- master
build:
context: host
image: centos_host
container_name: host01
hostname: host01
command: ["/var/run.sh"]
volumes:
- ansible_vol:/var/ans
networks:
- net
networks:
net:
volumes:
ansible_vol:
external: false
I need help understanding why my dockerfile does not work properly.
I created the image which I called hello-nodemon:
FROM node:latest
ENV HOME=/src/jv-agricultor
RUN mkdir -p $HOME/
WORKDIR $HOME/
ADD package* $HOME/
RUN npm install
EXPOSE 3000
ADD . $HOME/
CMD ["npm", "start"]
it works because when I run docker run -p 3000:3000 it works perfectly. But I want to use docker-compose.yml:
version: "3"
services:
web:
image: hello-nodemon
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "3000:3000"
networks:
- webnet
networks:
webnet:
So i used the commands: docker stack deploy -c docker-compose.yml webservice this return me:
ID NAME MODE REPLICAS IMAGE PORTS
y0furo1g22zs webservice_web replicated 5/5 hello-nodemon:latest *:3000->3000/tcp
So docker service ps y0furo1g22zs return me:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
nbgq8ln188dm webservice_web.1 hello-nodemon:latest abner Running Running 4 minutes ago
rrxjwudtorsm webservice_web.2 hello-nodemon:latest abner Running Running 4 minutes ago
7qrz9gtd4fan webservice_web.3 hello-nodemon:latest abner Running Running 4 minutes ago
lljmj01zlya8 webservice_web.4 hello-nodemon:latest abner Running Running 4 minutes ago
raqw3z0pdxqt webservice_web.5 hello-nodemon:latest abner Running Running 4 minutes ago
My containers
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6daf6afadfdc hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.1.nbgq8ln188dmz8q8qeb60scbz
2d74f8e9a728 hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.2.rrxjwudtorsm6to56t0srkzda
e3a3a039fdf9 hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.3.7qrz9gtd4fanju4zt6zx3afsf
7f08dbdf0c8d hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.5.raqw3z0pdxqtvkmkp00bp6tve
c6ce3762d6ae hello-nodemon:latest "npm start" 6 minutes ago Up 6 minutes 3000/tcp webservice_web.4.lljmj01zlya89gvmip5z0cf6f
but it does not work. The browser does not refuse but does not load the page; is infinitely searching.
I do not know what is happening, if someone helps me I will be very grateful.
This seems to be an issue with chrome only. I have the same issue in chrome, however, when I open in Firefox it works fine.
Here's how I fixed Chrome:
Looking into this more I think this was either and chrome issue or network issue as I was having the same issue:
Here is how I resolved it:
Make sure your /etc/hosts file has 127.0.0.1 localhost (more than likely it's already there)
Cleared Cookies and Cached files
Cleared host cache
Go to:chrome://net-internals/#dns click Clear Host Cache
Restarted chrome
Reset Network Adapter
Note: This was unintentional so not sure if it was part of the fix or not, but wanted to include it in case.
Unfortunately I'm not sure which step fixed the problem