Simple docker example only appears to expose db container and not web - django

I clone this repo (it's pretty much based on docker docs here) and run docker-compose up. Docker builds the 2 containers and I see the output from db_1 (psql looks to be completely ready) but nothing at all from web_1, no output whatsoever.
I go to my host IP + 8000 and nothing is running there. I am using docker toolbox for mac. It's pretty much the simplest possible example of using Docker - any idea why I'm not seeing anything from my Django container?
Thanks in advance,

it might be possible that STDOUT of the web_1 Container is mapped only to display WARN and ERROR level. You say youre using Docker Toolbox for Mac? Have you tried to reach the Website over the IP of the DockerToolBox VM or the HostIP? Im not quite aware with DockerToolbox since there is an native MacClient (https://docs.docker.com/engine/installation/mac/). Maybe try to reach the DockerToolboxIp not HostIP. I would also recommend to use Docker for Mac native, since i had problems with the ToolBox but none with the "Native" Client.
Hope i could Help

After taking a better look to the documentation I was able to start your containers.
After the git clone:
cd sane-django-docker
docker-compose up -d
This is the output
Starting sanedjangodocker_db_1
Starting sanedjangodocker_web_1
[root#localhost sane-django-docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cde9e93c1a70 sanedjangodocker_web "python3 manage.py ru" 19 seconds ago Up 1 seconds 0.0.0.0:8000->8000/tcp sanedjangodocker_web_1
73ad8cafe798 postgres:9.4 "/docker-entrypoint.s" 20 seconds ago Up 1 seconds 5432/tcp sanedjangodocker_db_1
When I just performd docker-compose up (running in the forground I saw this issue).
LOG: shutting down
LOG: database system is shut down
After taking a better look in the documentation I saw the problem
Django will complain about the postgres database not existing so we'll
create one:
docker exec sanedjangodocker_db_1 createdb -Upostgres webapp
Now the postgres is fine but I had to restart the webapp to find the db.
docker restart sanedjangodocker_web_1
Now I'm able to acces it on IP:8000
It worked!
Congratulations on your first Django-powered page.
I don't know how the django app really works but the setup is pretty strange.

Related

Appwrite environment variables ignored

I'm using Appwrite on AWS (started with the pre-canned Appwrite marketplace and upgraded to 0.14.2.305).
In order to allow certificate generation, I need to update _APP_DOMAIN and _APP_DOMAIN_TARGET. however, no matter which value I put there, it is not "ingested" by the app (container restart and reboot of the server did not make any difference)
I also tried to read the values from the docker instance itself - but again - no value was read.
Ideas?
You need to restart the Docker containers :)
Just run a docker compose up -d in your appwrite directory.

How to easily debug Redis and Django/Gunicorn when developing using Docker?

I'm not referring to more sophisticated debugging techniques, but how to get access to the same kind of error messages that are normally directed to terminal tabs?
Basically I'm adopting Docker in a Django project also using Redis.
In the old way of working I opened a linux terminal tab for gunicorn like this: gunicorn --reload --bind 0.0.0.0:8001 myapp.wsgi:application
And this tab kept running Gunicorn and any Python error was shown in this tab so I could see the problem and fix it.
I could also open a second tab for the celery woker: celery -A myapp worker --pool=solo -l info
The same thing happened, the tab was occupied by Celery and any Python error in a task was shown in the tab and I could see the problem and correct the code.
My question is: Using docker is there a way to make each of the containers direct these same errors that would previously go to the screen, to go to log files so that I can debug my code when an error occurs in Python?
What is the correct way to handle simple debugging during development using Docker containers?
After looking more about this in the docker documentation I found a link that solves this problem: View logs for a container or service
Basically the command "docker logs CONTAINER_ID" shows on the screen exactly what we would see in the terminal running the application.
Works perfectly to see Django, Redis and Angular logs.
Just type:
docker logs CONTAINER_ID
Replace the container_id keyword with the real id of the container you want to log in.
To find the id type:
docker ps

Make an http request to a docker container that lives in cloud with the use of nginx

I am new to docker. I have this docker container run on port 80 and living in a cloud instance. Docker assigns a private IP addresses to its containers by default. I was wondering what would be the necessary actions to take in order to have access to the running docker container outside of my cloud environment (something like http://mydockercontain.org). I have tried to use nginx to recreate a reverse proxy server in the cloud environment but it is not enough for someone outside of the cloud environment to make an http request to the running docker container. I know I have to setup some sort of DNS record mapping to the docker ip address but I'm really new to this technology and don't know what's the right approach to solve this problem.
I was in your shoes about 2-3 months ago, and at some point it just all made sense so bear with me here.
My favorite thing to do is to SSH in and run something to get the containerID's and see what containers are indeed running, like:
sudo docker ps -a
Next, run this to get into that container's logs so you can at least visually see what's going on in there:
sudo docker logs -f [CONTAINERID]
So now you'll at least be able to see a little about what's going on inside that given container. using the docker ps -a command, you can see what port it's running on and try to add that port onto the IP address you're trying to reach. ie. xxx.xx.xx.xx:8000 or something like that.
Still can't reach it?
I couldn't at this point... so from here I went back to square 1. In my Dockerfile, I found it easiest to use EXPOSE 80 to expose that port for when I want to build/run the container. Not sure how proficient you are with the DockerFile but it'd be a line that's only:
EXPOSE 80
The last change you might need to make is to control where your application is running. I'm a big python guy, so if its something like flask then you can easily change that in your app.run() by setting the host to 0.0.0.0 like app.run(host=0.0.0.0). Otherwise, your application will be running on 127.0.0.1, which would mean your app would only be reachable from inside the container which is the hard thing to grasp there if you're just starting off with Docker.
Once you have that ready, go back to run a few more commands... just make sure you have those containerID's handy from the docker ps -a command.
if its just one docker container:
sudo docker kill [CONTAINERID] # kill the old container
sudo docker rm [CONTAINERID] # remove the old container
sudo docker build [same build thing as before]
sudo docker run -d -p 80:80 [CONTAINER ID FROM BUILD ABOVE]
by using docker run -d -p 80:80, you're essentially binding it to the TCP/IP port available at the host and usually I can just access it at whatever the hosts IP address is by entering it in as the url. Of course, you may want to set up a VPC or something that restricts access to only a given whitelist of computers that you provide... I'm not entirely what cloud platform you're on but I'd recommend looking into that.
Next, depending on the cloud environment you're on, create a load balancer that can act as a reverse proxy in front of the containers running on those machines. That part is relatively plug and play as long as those containers are both running somewhere that the load balancer can reach them - so you may need to create a mini network/vpc that allows that communication. I'll be honest with you and say I haven't had enough experience in that realm to really give you many solid pointers beyond that.
I hope this helps point you in the right direction at the very least. Just keep on trying new things and experimenting and you'll solve it - trust me I know where you are and eventually you'll hit that point where everything suddenly makes perfect sense.

How do I get a podman/buildah container to run under CentOS on GCE?

1. Summarize the problem
I am following this simple tutorial from Developers RedHat to get a simple node/express container working.
I cannot get a container to run under a CentOS 7 VM on GCE.
I have a CentOS 7 GCE virtual machine, where I have Docker installed.
I am able to successfully build and run Docker containers and push them to Google's container registry with no problem.
Now I am trying to build podman/buildah containers, and do the same.
I have buildman/podman installed. When I run this:
podman build -t hello-world-nodejs .
I get the following error message:
cannot clone: Invalid argument user namespaces are not enabled in /proc/sys/user/max_user_namespaces Error: could not get runtime: cannot re-exec process
any ideas?
Additionally, if there are any guides into getting this image into Google's container registry, and running under Cloud Run, it would be greatly appreciated.
Ultimately the destination for some containers is a cloud service.
2. Provide background including what you've already tried
I have tried doing a web search for a solution, nothing found that has solved the problem so far.
3. Show some code
podman build -t hello-world-nodejs .
4. Describe expected and actual results including any error messages
I can create and run docker images/containers on this GCE VM, I am trying to do the same with buildah/podman.
The following solved this issue for me:
sudo bash -c 'echo 10000 > /proc/sys/user/max_user_namespaces'
sudo bash -c "echo $(whoami):110000:65536 > /etc/subuid"
sudo bash -c "echo $(whoami):110000:65536 > /etc/subgid"
And then if you encounter an errors related to lchown run the following:
sudo rm -rf ~/.{config,local/share}/containers /run/user/$(id -u)/{libpod,runc,vfs-*}
I have spun up a CentOS 7 VM on GCE and got same issue. The issue is caused because User Namespaces is not enabled on the kernel by default. You have 2 options, either running podman as root (or using sudo) or enabling User Namespaces in your CentOS VM (the hard way).
According to the post here, the use of user namespace and the allocations of uid and gid’s that are required to make rootless containers work securely in your environment.
Probably StackOverflow is not the best place to ask this question. It's better to ask in the ServerFault site since it's a server and not coding problem.

Getting ember to run under docker on Windows Quickstart

Working through this tutorial on setting up ember-cli in a Docker container:
http://www.rkblog.rk.edu.pl/w/p/setting-ember-cli-development-environment-ember-21/
Here are my steps:
Created docker-compose.yml in an empty folder on the host machine
Launched Docker Quickstart to get a terminal
Changed to the folder with the .yml
Ran the two docker-compose commands below from the terminal (added -d because without that you get a message that interactive mode is not supported)
Ran docker ps -a to verify that the container was running
Ran docker inspect CONTAINER_ID to find the ip address of the running container
Found the IP address at an odd location (172.17.0.2)
Attempted to access port 4200 on that IP from the host Windows machine browser and also from the Docker CL via curl but without success.
Ran docker ps -a and found that both containers that had been instantiated had exited.
Now if I try to start the container again it just exits immediately
docker-compose run -d --rm ember init
docker-compose run -d --rm ember server
What am I missing to get up and running? Do I need to open ports on the Default VM running in Virtualbox? How do I diagnose why the container keeps exiting?
First I would suggest using docker-compose up, that is most likely what you want.
To see the logs for a detached container you can run docker logs <container name>. If there are any errors you'll see them there.
A likely cause of the "container exit" is because the process goes into the background. Docker requires a process to stay in the foreground, but many serve commands will background by default. To keep the process in the foreground you can sometimes add use a flag like --foreground or --no-daemon, but I'm not sure if one exists for ember.
If that flag doesn't exist, it's likely that ember server is just checking if stdin/stdout are connected to a tty. By default they are not. You can add these lines to your docker-compose.yml to fix it:
stdin_open: True
tty: True
Ok finally resolved it. The issue with the module resolution may have been long file name resolution on windows because after I moved the source folder to the root of the host I was able to get ember serve running under windows.
Then from the terminal window I ran the commands to init and launch ember-server
docker-compose run -d --rm ember init
docker-compose run -d --rm ember server
Then did:
docker-compose up -d
which launched the containers successfully and then I was able to access the Ember page served up at the IP:Port specified earlier in the comments
http://192.168.99.100:4200/