How do I enter my container if dokku enter <app> does nothing? - dokku

I have a simple dokku app using herokuish buildpack-php with a procfile: web: vendor/bin/heroku-php-apache2 public/
If I try to enter the app with dokku enter <appname> nothing happens, and I am simply returned to my host shell.
I can run dokku run <appname> bash and get a shell, but is, as far as I understand from the documentation placing me in a new container and not in the existing/running one I need access to:
The run command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container.
How can I fix this so I can enter my running container?

If you are in the local directory for your app, doing the following will take you into the running container for it:
dokku enter web.1
I've done this a few times today!

As a workaround, you can enter your container using docker. For doing so, run docker ps and note the container ID. Afterwards, run docker exec -it container_id /bin/bash.

Related

how to share data between docker container and host

I'm working on a read the docs documentation where I use docker. To customize it, I d like to share the css folder between the container and host, in order to avoid building always a new image to see the changes. The goal is, that I can just refresh the browser and see the changes.
I tried something like this, but it doesn't work:
docker run -v ~/docs/source/_static/css:/docs/source/_static/css -p 80:80 -it my-docu:latest
What is wrong in this command?
The path of the folder I'd like to share is:
Documents/my-documentation/docs/source/_static/css
Thanks for your help!
I'm guessing that the ~ does not resolve correctly. The tilde character ("~") refers to the home directory of your user; usually something like /home/your_username.
In your case, it sounds like your document isn't in this directory anyway.
Try:
docker run -v Documents/my-documentation/docs/source/_static/css:/docs/source/_static/css -p 80:80 -it my-docu:latest
I have no mac to test with, but I suspect the command should be as below (Documents is a subfolder to inside your home directory denoted by ~)
docker run -v ~/Documents/my-documentation/docs/source/_static/css:/docs/source/_static/css -p 80:80 -it my-docu:latest
In your OP you mount the host folder ~/docs/source/_static/css, which does not make sense if your files are in Documents/my-documentation/docs/source/_static/css as that would correspond to ~/Documents/my-documentation/docs/source/_static/css
Keep in mind that Docker is still running inside a VM on Mac, so you will need to give a host path that is valid on that VM
What you can do to get a better view of the situation is to start an interactive container where you mount the root file system of the host vm root into /mnt/vm-root. That way you can see what paths are available to mount and how they should be formatted when you pass them using the -v flag to the docker run command
docker run --rm -it -w /mnt/vm-root -v /:/mnt/vm-root ubuntu:latest bash

Docker shows inconsistent behaviour when creating container from image

I am developing a web application which depends on a moodle system, as it uses moodles webservices. For my automated tests, I wanted to use docker to provide a preconfigured moodle-application on all my machines. Therefore I created a docker image, which I import from a .tar.gz file.
However, creating a new container-instance from this image behaves inconsistently. Sometimes the container boots up correctly and everything works fine. However, sometimes the container starts but the moodle-website is not reachable. If I connect my bash to the container using docker exec -it <container> bash I see that apache is running. The error logs do not show any entries which might be related to this issue.
If I kill the container instance and boot it up again, everything works as expected (sometimes this step has to be repeated multiple times). Do you have any idea what could be the reason for this strange behaviour? Anyone experiencing similar issues?
Docker is running on Ubuntu 14:04. The problem appears on several machines. The script which imports the image and starts the container looks like this:
#!/usr/bin/env bash
docker rm -f moodle
docker load < my-moodle.tar.gz
docker run -d -p 8080:80 -p 8443:443 -p 3306:3306 --name moodle moodle-image
Thanks in advance!
Successful container startup depends on your container entrypoint and external resources (if the entrypoint has external dependencies). What is the entrypoint? Does it depend on external resources?

Is it safe to remove Docker containers listed with `docker ps -f status=created`?

I've already seen posts showing how to remove exited containers listed with docker ps -q -f status=exited, but I also want to clean up 'created' but not 'running' containers. Is it safe to remove containers with the 'created' status, or is there a downside to this?
Docker containers with created status are containers which are created from the images, but never started. Removing them has no impact as you would not have run any process within the container and causing a change in the state of the created container, in the later case requires to be committed. This is generally done to speed up starting the container and making sure all the configuration is kept ready.
Refer Docker Docs
The docker create command creates a writeable container layer over the
specified image and prepares it for running the specified command. The
container ID is then printed to STDOUT. This is similar to docker run
-d except the container is never started. You can then use the docker start command to start the container at any point.
This is useful when you want to set up a container configuration ahead
of time so that it is ready to start when you need it. The initial
status of the new container is created.
There is two possibility for a container to be in the created status :
As explained by #askb docker container created from the image using docker create command will end up in the create command
A docker container created by the run command but not able to start. Multiple causes here but the easiestone is a docker container with a port mapping to an already bind ones
To answer the question, in both cases, removing them is safe.
A way to reproduce the docker container in a created state via the run command is :
docker pull loicmathieu/vsftpd
docker run -p 621:21 -d loicmathieu/vsftpd ftp
docker run -p 621:21 -d loicmathieu/vsftpd ftp
Then docker ps -a will give you something like
CONTAINER ID IMAGE COMMAND CREATED STATUS
e60dcd51e4e2 loicmathieu/vsftpd "/start.sh ftp" 6 seconds ago Created
7041c77cad53 loicmathieu/vsftpd "/start.sh ftp" 16 seconds ago Up 15 seconds

docker cannot start service from DockFile

In my dockerFile ,
I tried to do
service myapp start;
But when I start the container :
docker run -it myapp_image service myapp status
>dead but pid file exists
However if I get into the conainer , and start it manually, it ran without problem
docker run -it myapp_image /bin/bash
bash-3.2$ service myapp restart
bash-3.2$ service myapp status
> myapp is running.
Any workaround to get the service running from DockerFile ?
service myapp start will start your app as a service in the background. As soon as this command exists, the docker container will stop. This is the expected behavior for Docker containers.
What you want to do is to have the CMD instruction start your app in the foreground instead of in the background.
If you put in your Dockerfile CMD service myapp start, but then you run the image you have compiled with it passing service myapp status as starting command, you override the CMD command. So your start command is not executed. If you myapp print something when it starts, try doing
docker logs your_container_id
to see if there is the output you expect. Or put as your starting command a script which starts your myapp and then it queries for its status. Then, with logs command, you can see if it is running or not.
The container will live as long as command you pass as parameter of docker run, i.e. as long the "service" program is running.
You may launch your server in the foreground, or run a command that launch the server in background (and maybe more things) and keep living doing more things, i.e. monit or supervisord in foreground to relaunch the server if it ends.

Dokku view logs? (hosted on digitalocean)

So I just started using dokku (with postegres). My app works on Heroku so I'm pretty sure it's a deployment issue. The app seems to be running but is however hitting issues at log in. I did dokku logs my_app_name however the logs seems to be old. On heroku whenever there is an issue there is an corresponding log, but here I cannot find.
Any ideas are appreciated! Thanks!
To get a continuous log you can type:
dokku logs yourappname -t
It acts as the tail -f command on linux and mac systems.
Dokku logs - docs
I think you can try to use docker logs -f `cat /home/dokku/<app-name>/CONTAINER for getting access to the logs.
In case if you want to see the logs of the specific container:
docker ps
then find your container with postgresql for example and run docker logs -f <CONTAINER_ID>
I hope it could help you to find out the problem.
Out of the topic I found dokku-alt and using it in my current DO image. If you are working with Ruby it's working out of the box comparing with original dokku project.
The easiest:
dokku logs -t *app_name*
up to 300000 lines:
dokku logs -t -n 300000 *app_name* > logs.txt
complete log of container: (needs to be executed on server)
docker container list # to get the container id
docker logs *container_id* > logs.txt
It may not be the answer you are looking for but I was seeing the same issue. I just waited about 30 seconds and the logs were updated. I don't know why they are updated live, but they eventually came through.

Resources