Ctrl-P and Ctrl-N Behaving Unexpectedly Under Docker

Ctrl-p and Ctrl-n behaving unexpectedly under Docker

It looks like this has been removed (or moved) in the Docs, but it used to live here: https://docs.docker.com/engine/reference/commandline/attach/

Edit: It looks like they reference the below in the Configuration Files documentation.

The command sequence to detach from a docker container is ctrl-p ctrl-q, which is why ctrl-p doesn't work as expected. When you hit ctrl-p, docker is waiting on ctrl-q, so nothing happens.

You can use the new --detach-keys argument to docker run to override this sequence to be something other than ctrl-p:

docker run -ti --detach-keys="ctrl-@" ubuntu:14.04 bash

$# ls
$# <--- Ctrl-P here will display ls now
$# <--- Ctrl-@ here will detach from the running container

If you want, you can add this to your ~/.docker/config.json file to persist this change:

{
...
"detachKeys": "ctrl-@",
...
}

More details on this can be found here: https://github.com/docker/docker/pull/15666 as I can't find it in the docs anymore.

kubectl exec ... /bin/bash eating control-p?

If you're using tmux, adding this line to tmux.conf helped me to workaround this issue:

bind -n C-p send Up

docker: driver failed programming external connectivity on endpoint webserver

From your error message, the EADDRINUSE indicates port 80 is already in use on either the docker VM or possibly directly on your laptop. You can either stop whatever is running on that port, or change the port used in your Docker, command. To change to the external port 8080, use:

docker run -d -p 8080:80 --name webserver nginx

Can't connect to MySQL running in docker

After checking if the ports are mapped correctky and also verified da alocal mysqlclient can connect to the server, there is another possibiliry.

MySQL is in default configuration as security measure , only accepting access from the localhost.

So you have to control and change the following parameter in the my.cnf

[mysqld] 
bind-address=0.0.0.0

That would allow access from every ip

Additionally by default root has privileges for localhost only so it's not allowed to connect with that user from another hosts. To fix that we can execute following SQL commands from within container:

GRANT CREATE USER ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;

Another option would be to create separate user (by runnin corresponding SQL from within container).

Why docker container exits immediately

A docker container exits when its main process finishes.

In this case it will exit when your start-all.sh script ends. I don't know enough about hadoop to tell you how to do it in this case, but you need to either leave something running in the foreground or use a process manager such as runit or supervisord to run the processes.

I think you must be mistaken about it working if you don't specify -d; it should have exactly the same effect. I suspect you launched it with a slightly different command or using -it which will change things.

A simple solution may be to add something like:

while true; do sleep 1000; done

to the end of the script. I don't like this however, as the script should really be monitoring the processes it kicked off.

(I should say I stole that code from https://github.com/sequenceiq/hadoop-docker/blob/master/bootstrap.sh)

Deploying a minimal flask app in docker - server connection issues

The problem is you are only binding to the localhost interface, you should be binding to 0.0.0.0 if you want the container to be accessible from outside. If you change:

if __name__ == '__main__':
app.run()

to

if __name__ == '__main__':
app.run(host='0.0.0.0')

It should work.

Note that this will bind to all interfaces on the host, which may in some circumstances be a security risk - see https://stackoverflow.com/a/58138250/4332 for more information on binding to a specific interface.

docker: executable file not found in $PATH

When you use the exec format for a command (e.g., CMD ["grunt"], a JSON array with double quotes), it will be executed without a shell. This means that most environment variables will not be present.

If you specify your command as a regular string (e.g. CMD grunt) then the string after CMD will be executed with /bin/sh -c.

More info on this is available in the CMD section of the Dockerfile reference.

Docker: Is the server running on host localhost (::1) and accepting TCP/IP connections on port 5432?

The issue is that you are trying to connect to localhost inside the container for DB. The port mapping that you do 5432:5432 for postgres map 5432 to localhost of your host machine.

Now your web container code is running inside the container. And there is nothing on its localhost:5432.

So you need to change your connection details in the config to connect to postgres:5432 and this is because you named the postgres DB service as postgres

Change that and it should work.



Related Topics



Leave a reply



Submit