I'm just using docker for first time and I copy it on the internet
This is my file
Dockerfile
FROM mysql:oracle
COPY dbscript.sql /docker-entrypoint-initdb.d/
and I build it with this command
docker build -t mysqllab
after built I run it
docker run -d --name mysqllabtest -e MYSQL_ROOT_PASSWORD='abc123' mysqllab
it's run and get the message of container id, so I run
docker ps
to see what my container is running but it's don't have this container, I try it again with fast docker ps so I see it run for 4 seconds and terminate
What Can I do with this?
I just use
docker logs mysqllabtest
for check something wrong it about MySQL script so after I edited it It's works! thanks #Hans Kilian for tell me this command
Related
I am trying to use a MySQL image on docker, attaching a volume, furthermore I would like to add a sql script in order to create a table if not present yet.
So if the container is used in another machine the table will be Always present.
My command :
docker run -d -p 3306:3306 --name my-mysql --network sma -v /scripts:/docker-entrypoint-initdb.d/ -v /myvolume/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=myDB mysql
My situation:
I am able to attach the volume with -v option (/myvolume/:/var/lib/mysql) during the run, and actually I am also able to insert the script in the init directory ( /docker-entrypoint-initdb.d/ ) but if I do these two things, only the volume attaching will work.
I guess it is something like the script is executed (because it is placed in the directory) but then the MySQL is overwritten by the volume attaching, so the only thing I am seeing is what is present in myvolume.
There is some way that makes that work?
I resolved using it in a swarm from a docker-compose with docker stack deploy -c docker-compose.yml swarm_name.
In the service definition of the docker-compose I added the command line in order to force it to execute the init script.
command: --init-file /docker-entrypoint-initdb.d/initDb.sql
Hi there,
I'm trying to create a docker container that will run a mysql script which generates a database and then table. My Dockerfile looks like this:
FROM mysql:latest
WORKDIR /
ADD . /
EXPOSE 3306
CMD mysql -u "root" -proot < "schema.sql"
I create the image through this:
docker build -t database .
And then I run it through this:
docker run -d -p 3306:3306 database
At this point the script should be run- however instead I just get this random line in the terminal:
0b2503b42482a4fa840351925845392e1abdf6022b23447187ff49ed4f0fa05b
Grateful for your help!
you are getting 0b2503b42482a4fa840351925845392e1abdf6022b23447187ff49ed4f0fa05b because of the option "-d" in docker run -d -p 3306:3306 database which indicates that the container will be running in the background. You can remove it if you dont want that.
For more info about this please check this link: Docker run command
The container should be running though.
Check the command Docker ps that will show you infos about running containers.
Hope this helps!
don't worry, this is 0b2503b42482a4fa840351925845392e1abdf6022b23447187ff49ed4f0fa05b ID from container.
You can use id to stop or check status or collect information of container. if you want check your command is work or not, you can run with this command docker run -it database bash or docker run -it database sh
Hope this helps.
Best Regards
as you are overriding CMD entry command in docker file, you would need to start mysqld service explicitly
CMD [mysqld, mysql -u "root" -proot < "schema.sql"]
all
Currently, I have written a service in the docker container.
Currently, when I exit from my container my service is not running which is expected but when I see
"sudo docker exec -it ps -ef" it shows that MySQL which is installed in my container is up and running if I want the same kind of behavior to my service then what should I do?
Thanks in advance.
You want to run your container detached* with
docker run -d <image_name>
Thanks
Start learning docker and try to setup a mysql container. But it dies immediately with Exited(1).
Following is the command used
docker run mysql -e MYSQL_ROOT_PASSWORD=password1
Looking at docker ps, it does not show any running docker container
with docker ps -a returns the following :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e681f56c52e2 mysql "/entrypoint.sh -e MY" 3 seconds ago Exited(1) 3 seconds ago lonely_rosalind
Nothing shows up for docker logs lonley_rosalind either
Any idea how to determine why if failed ?
I am running
ubuntu 15.04
docker version 1.9.1 build a34a1d5
Try this
docker run -e MYSQL_ROOT_PASSWORD=password1 mysql
When you are writing something after docker image name docker accepts it as a command for execution in your created container. Pattern for docker run:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
I want to run a mysql container in Docker. The Dockerfile that I use is the Dockerfile defined in the official repo[here].
I only extended this Dockerfile with 2 more lines so I can import a init sql file, like this :
ADD my-init-file.sql /my-init-file.sql
CMD ["mysqld", "--init-file=/my-init-file.sql"]
I want to run this instance as a daemon but when I execute this command, from the documentation:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
The container exits automatically. I want to run it as a daemon so I can link apps(like a wordpress site) in another container to the mysql database.
Maybe I am missing something. Can anyone show me how ?
[EDIT] I forgot to say that I ran docker logs my-container after starting the container and there is no error :
Running mysql_install_db ...
Finished mysql_install_db
docker ps shows no running container.
My guess is the command executes successfully but the mysqld daemon does not start.
Your Dockerfile seems fine. Your init file may be buggy, though. If MySQL terminates, then the container will terminate.
The first debug step is to look at the logs:
docker logs some-mysql
You can use this whether the container is stopped or running. Hopefully, you'll see something obvious, like you missed some semicolons.
If the logs don't help, the next thing to try is to get inside the container and see what's happening first-hand
docker run -e MYSQL_ROOT_PASSWORD=mysecretpassword -it mysql /bin/bash
This will get you a Bash shell inside your container. Then you can run
mysqld --init-file=/my-init-file.sql
And see what happens. Maybe something in your init file tells MySQL to exit cleanly, so you get no logs but the command terminates.
Dmitri, after you made docker run with -d argument your container detached and already working as daemon if only CMD command not returned exit code.
You can check running containers by docker ps command.
You can check all containers by running docker ps -a.
Also i think you will need to open mysql port outside the container. You can do it with -P argument or better way to make communication between containers is docker links.