Mariadb failure to daemonise with docker - docker

I'm trying to use this image https://hub.docker.com/_/mariadb/ (any version).
I'm using the following to launch the container:
cd maria
docker build -t maria-image .
docker run --name maria maria-image -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1
cd ..
I'm preparing a custom build in case I need to do any future modifications so that lives in maria/Dockerfile with the following:
FROM mariadb:5.5
MAINTAINER ...
EXPOSE 3306
If I do docker ps -a I get status "Exited (2) 5 seconds ago".

Your args appear to be in the wrong order, maria-image should be after all other docker run args:
docker run --name maria -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 maria-image
The version you ran passed the -d and -e as the command for docker to run. Note that you'll want to first run docker rm -v maria to free the container name for reuse.

Related

docker run - autokill container already in use?

I was following this guide on customizing MySQL databases in Docker, and ran this command multiple times after making tweaks to the mounted sql files:
docker run -d -p 3306:3306 --name my-mysql -v /Users/pneedham/dev/docker-testing/sql-scripts:/docker-entrypoint-initdb.d/ -e MYSQL_ROOT_PASSWORD=supersecret -e MYSQL_DATABASE=company mysql
On all subsequent executions of that command, I would see an error like this:
docker: Error response from daemon: Conflict. The container name "/my-mysql" is already in use by container "9dc103de93b7ad0166bb359645c12d49e0aa4a3f2330b5980e455cec24843663". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
What I'd like to know is whether that docker run command can be modified to auto-kill the previous container (if it exists)? Or if there is a different command that has the same desired result.
If I were to create a shell script to do that for me, I'd first run docker ps -aqf "name=mysql" and if there is any output, use that resulting container ID by running docker rm -f $containerID. And then run the original command.
docker run command has a --rm arguments that deletes the container after the run is completed. see the docs . So, just change your command to
docker run --rm -d -p 3306:3306 --name my-mysql -v /Users/pneedham/dev/docker-testing/sql-scripts:/docker-entrypoint-initdb.d/ -e MYSQL_ROOT_PASSWORD=supersecret -e MYSQL_DATABASE=company mysql

What does the "." in "docker run <image> . " do?

I have 2 commands:
docker run -d -p 5000:8080 ${image_name} .
and
docker run -d -p 5000:8080 ${image_name}
The only difference between these two commands is the period at the end. What is the purpose of the period? I understand that it signifies the current directory, but what is its use in a command like this?
Arguments after the image name are passed to the image's entrypoint, so it depends on the default ENTRYPOINT of the image. Often, the entrypoint is bash, so running
docker run -d -p 5000:8080 ${image_name} .
Is like running bash ..
The fact that you are publishing ports in your docker run command makes me think that the image runs a server. Let's say the entrypoint of your image is python server.py. Then the command
docker run -d -p 5000:8080 ${image_name} .
is akin to running python server.py .
and the command
docker run -d -p 5000:8080 ${image_name}
is akin to running python server.py (note the absence of the dot).

why do i keep seeing nginx index.html on localhost when i run my docker image

I installed and run nginx on my linux machine to understand the configurations etc. After a while i decided to remove it safely by following this thread in order to use it in docker
By following this documentaion i run this command
sudo docker run --name ngix -d -p 8080:80 pillalexakis/myrestapi:01
And i saw ngix's homepage at localhost
Then i deleted all ngix images & stopped all containers and i also run this command
sudo docker system prune -a
But now restarted my service by this command
sudo docker run -p 192.168.2.9:7777:8085 phillalexakis/myfirstapi:01 and i keep seeing at localhost ngix index.html
How can i totally remove it ?
Note: I'm new with docker and i might have missed a lot of things. Let me know what extra docker commands should i run in order provide better information.
Assuming your host have been preparing as below
your files (index.html, js, etc) under folder - /myhost/nginx/html
your nginx configuration - /myhost/nginx/nginx.conf
Solution
map your files (call volume) on the fly from outside docker image via docker cli
This is the command
docker run -it --rm -d -p 8080:80 --name web \
-v /myhost/nginx/html:/usr/share/nginx/html \
-v /myhost/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx
copy your files into docker image by build your own docker image via Dockerfile
This is your Dockerfile under /myhost/nginx
FROM nginx:latest
COPY ./html/index.html /usr/share/nginx/html/index.html
This is the command to build your docker image
cd /myhost/nginx
docker build -t pillalexakis/nginx .
This is the command to run your docker image
docker run -it --rm -d -p 8080:80 --name web \
pillalexakis/nginx

Alpine execute command in a new shell

I'm using an Alpine image in docker and I wanted to know if there is a command to open a new terminal and execute a command.
Like :
gnome-terminal -e <command>
I've already searched in ash man but didn't find what I wanted
You always have a choice of running commands on running containers irrespective of the OS type.
docker image pull nginx
docker container run -d --name nginx -p 80:80 nginx
docker exec -ti nginx sh -c "echo 'Hello World'"

How to run a database independent of a Rails app?

How can I separate a database and rails app into two different containers? The tutorial on Docker shows how to create the two with the docker-compose set-up, however I'm more curious on how to set this up manually so that I can play around with SOA on Docker.
Create an instance of your db container
db stop/rm/pull/run:
# First three lines are for teardown/reubuild
#!/bin/bash
docker stop myapp-postgres
docker rm myapp-postgres
docker pull postgres
docker run --name myapp-postgres -t -i -d postgres
app stop/rm/pull/run:
#!/bin/bash
docker stop myapp
docker rm myapp
docker pull dockerhubname/myapp
docker run -d -t -i --link myapp-postgres:postgres -p 80:80 --name myapp dockerhubname/myapp
#spit out some useful info
docker ps
MYAPP_MACHINE=$(docker ps | grep myapp | awk '{print $1}')
echo $MYAPP_MACHINE
docker exec -ti $MYAPP_MACHINE ps -aux

Resources