I just want to create a service on Docker Swarm with NGINX and to make data persistent after docker-machine reboot.
I check the manager IP
docker-machine ip manager
Then I go to the machine
docker-machine ssh manager
Inside a Docker Machine I create a new service:
docker service create -p 80:80 --mount type=volume,target=/usr/share/nginx/html --name nginx nginx
Here I expect to have a service running with NGINX on the port 80 with an unnamed volume.
In a web browser I see that NGINX is online at MANAGER_IP:80.
With docker inspect CONTAINER_ID can find the path to the volume and to modify e.g. index.html.
But after docker-machine stop and docker-machine start my change disappears.
Why? What do I have to do to make it persistent (to be available after rebooting docker-machine) ?
Any advice much appreciated.
can you try this
docker service create -p 80:80 --mount type=volume,source=myvolume,destination=/usr/share/nginx/html --name nginx nginx
You just didn't mention the source in your command
Related
When using Docker Compose, how can we determine and set the IP address of the Docker host in the /etc/hosts file of the Docker container when the host is running Linux? I will like a hostname like DOCKER_HOST in the container to refer to the Docker host.
Docker for Linux does not yet support host.docker.internal, unlike Docker for Windows and Docker for Mac, so we need an alternative to this.
--network host cannot be used here because for my purpose localhost in the container must still refer to the container itself.
Docker Compose supports using extra_hosts to add a hostname-ip mapping in /etc/hosts, but I am unable to figure out how to automatically determine the host IP address to be used.
version: '3'
services:
api:
build: .
ports:
- "8080:8080"
extra_hosts:
- "DOCKER_HOST:X.X.X.X" # <=== How do we automatically set this IP address?
Is it possible to do something like the following, where we do not have to manually define the Docker host IP address when starting the containers?
DOCKER_HOST=`command_to_get_host_ip` docker-compose up -d
Or can we set a static IP for the Docker host in docker-compose.yml?
You can try :
DOCKER_HOST=$(python -c 'import socket;print(socket.gethostbyname(socket.gethostname()))') docker-compose up -d
I'm trying to deploy Apache Ignite Web console on Linux(CentOS 7), but to run docker, i have to set host_absolute_path of MongoDB, How to handle it?
<host_absolute_path> is a path on your host machine where MongoDB will create database files. This folder should be created before docker run. Go to Docker->Preferences->File Sharing and create the directory there or use the other way that suits your more.
Can anybody explain step by step?
docker run -d -p 80:80 -v <host_absolute_path>:/var/lib/mongodb --name web-console-standalone apacheignite/web-console-standalone
<host_absolute_path> is just a path on your local machine. MongoDB is embedded into the docker image. You need to specify a path where MongoDB will store data.
It's required because data need to survive restarts of the container. For example you can run:
docker run -it --rm -p 8080:80 -v /home/user/mongodb:/var/lib/mongodb apacheignite/web-console-standalone:2.7.0
It will run Web console 2.7.0 on 8080 port of the host machine and store data in /home/user/mongodb. This directory should be already present when you start the container.
For Windows:
something like below worked
docker run -d -p 80:80 -v D:\Softwares\IgniteProject\MangoDB:/var/lib/mongodb --name web-console-standalone apacheignite/web-console-standalone
I am trying to pull registry image from docker.
docker run -d -p 5000:5000 --restart=always --name registry registry:2
But it gives an error like below:
docker: Error while pulling image: Get https://index.docker.io/v1/repositories/library/registry/images: dial tcp 52.73.159.23:443: getsockopt: no route to host.
I have set the proxy but it doesn't help. What could be the problem? I am running on Redhat linux 7.
If you are behind an HTTP proxy server, for example in corporate settings, you will need to add configure the Docker systemd service file.
First, create a systemd drop-in directory for the docker service:
mkdir /etc/systemd/system/docker.service.d
Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Flush changes:systemctl daemon-reload
Restart Docker: systemctl restart docker
see https://docs.docker.com/engine/admin/systemd/#http-proxy for details.
I have the docker container with jar file to run and i run the container by
sudo docker run --name xxx -d imagename
after the jar file was run successfully,then the container became inactive condition.
I want to restart the container automatically in amazon web service .
Have a look at the restart policies Docker provides. Maybe that is the solution for you?
Docker Restart Policies
Looking at shipyard, I noticed that the deploy container launches containers on the host ( redis, router, database, load balancer, shipyard)
This is done by using the -H flag.
So I decided to try this to deploy my apps as this would make deployment tons easier ( versus systemd, init.d ).
I was able to get about 70% there, but the thing that broke was --volumes-from tag.
The container starts, but the volume it's mounting to is empty. I have a simple example posted here.
http://goo.gl/a558XL
If you run these commands on host. it works fine.
on_host$ docker run --name data joshuacalloway/data
on_host$ docker run --volumes-from data ubuntu cat /data/hello.txt
However if you do this in a container. It is broken.
on_host$ docker run -it --entrypoint=/bin/bash -v /var/run/docker.sock:/var/run/docker.sock joshuacalloway/deploy -s
in_container:/# docker ps -----> this shows docker processes on the host
in_container:/# docker rm data ---> this removes docker container data that was created above
in_container:/# docker run --name data joshuacalloway/data
in_container:/# docker run --volumes-from data ubuntu cat /data/hello.txt