Docker run command, volumes error when using relative paths - docker

I'm trying to make a docker run and build command out of the compose file below.
So far I have come up with this:
docker build --tag testenvironment/nodejs ./node_js
docker run -p 8080:8080 -v ./node_js:/home/app/chat -v /home/app/chat/node_modules --name nodejs testenvironment/nodejs
I'm stuck here because it gives the following error:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: create ./node_js: "./node_js" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intented to pass a host directory, use absolute path. See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.
Compose file:
node:
build: ./node_js
command: node server.js
depends_on:
- mongo
links:
- mongo
environment:
NODE_ENV: development
ports:
- '8080:8080'
volumes:
- ./node_js:/home/app/chat
- /home/app/chat/node_modules
Can anybody tell me how to convert the volumes from the compose file to a docker run command? Thanks in advance.
I am using the Docker Toolbox for Windows 10.

This part:
docker run -p 8080:8080 -v ./node_js:/home/app/chat ....
Should be:
docker run -p 8080:8080 -v $(pwd)/node_js:/home/app/chat
docker run requires an absolute path for volumes (as a difference from compose)

You have to use an absolute path when adding a volume in Windows, which can be in the following formats:
docker run -p 8080:8080 -v //c/users/desktop/path/to/node_js:/home/app/chat
docker run -p 8080:8080 -v C://users/desktop/path/to/node_js:/home/app/chat

Related

Portainer - no matching manifest for unknown in the manifest list entries - install error

I have tried executing below command to run portainer.
In Native Windows containers. Windows Server 2016 Datacenter.
$ docker run -d -p 9000:9000 -p 8000:8000 --name portainer --restart always -v \.\pipe\docker_engine:\.\pipe\docker_engine -v C:\ProgramData\Portainer:C:\data portainer/portainer
This is the error I am getting, "no matching manifest for unknown in the manifest list entries."
Any idea?
Hi pl run docker pull portainer/portainer and see if it runs successfully. Hope docker service port (default 2375) is allowed on windows firewall

Why can't my my modified copy of the docker elasticsearch be accessed from a browser?

I am attempting to run a customized image based on the official Elasticsearch image from Docker. However, when I try to access it through localhost:9200, it does not work.
I created a custom-elasticsearch.yml file with host set to 127.0.0.1 (localhost), then build an elasticsearch-custom image and ran it. Steps can be found in the link below.
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/docker.html
When I try to access the elasticsearch through a browser at localhost:9200, it fails to connect. How do I repair this?
Code in Dockerfile for elasticsearch-custom
FROM docker.elastic.co/elasticsearch/elasticsearch:6.4.3
COPY --chown=elasticsearch:elasticsearch elasticsearch.yml /usr/share/elasticsearch/config/
Building the custom docker
docker build --tag=elasticsearch-custom .
Method to run elasticsearch-custom
docker run -d -ti -v /usr/share/elasticsearch/data -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch-custom
When I type localhost:9200 into the browser, I expect it to return the data from the elasticsearch.
But instead the browser says it is unable to connect.
You need to add the following parameter to Docker run command, so your container and the host os will share the same network interface. Then you should be able to access Docker container with localhost:9200
--network=host
The final run command should be like this;
docker run -d -ti -v /usr/share/elasticsearch/data --network=host -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch-custom

Run docker-compose without installation

I try to run docker-compose without installation, so using docker:compose repository (with docker run).
So I tried this way :
docker run -ti --rm -v $PWD:/XXX docker/compose:1.24.1 up -d
The problem is that I don't know the container dir name of docker/compose (here XXX) to mount my current folder as volume.
Any ideas...?
Thanks !
You can bind mount your local docker-compose.yaml to any place just remember to tell docker-compose use -f, like next:
docker run -ti --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/code docker/compose:1.24.1 -f /code/docker-compose.yaml up -d
Meanwhile, don't forget to add docker.sock of your host machine bind mount to the container.
That XXX folder can be anything inside the container. Basically in -v option of docker run. Its -v [host-directory]:[container-directory].
If you are trying to run a docker-compose up inside the container, then follow these steps:
Create a directory on host mkdir /root/test
Create docker-compose.yaml file with following contents:
version: '2'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: redis
Run docker run command to run docker-compose inside the container.
docker run -itd -v /var/run/docker.sock:/var/run/docker.sock -v /root/test/:/var/tmp/ docker/compose:1.24.1 -f /var/tmp/docker-compose.yaml up -d
NOTE: Here /var/tmp directory inside the container will contain docker-compose.yaml file so I have used -f option to specify complete path of the yaml file.
Hope this helps.

Invalid volume specification trying to run portainer container

I'm trying to deploy portainer to my local docker. I'm running the Docker CE 18.0.6.0 version on Windows 10. I tried to follow the steps from these two pages:
Portainer-Deployment
Tutorial: Portainer for local Docker environments on Windows
10!
But all the times I have tried to run the following command:
docker run -d -p 9000:9000 --name portainer --restart always -v portainer_data:/data portainer/portainer -H tcp://10.0.75.1:2375
Docker responds always with the same message:
Error response from daemon: invalid volume specification:
'portainer_data:/data'
I created the volume using this command:
docker volume create portainer_data
Any idea what could be?
The path syntax you used only works for Linux containers since Linux environments only have a single root to their filesystem tree. To run portainer container in a native Windows container, the syntax is:
docker run -d -p 9000:9000 --name portainer --restart always -v \\.\pipe\docker_engine:\\.\pipe\docker_engine -v C:\ProgramData\Portainer:C:\data portainer/portainer
This comes from the deployment documentation.

Execute command in linked docker container

Is there any way posible to exec command from inside one docker container in the linked docker container?
I don't want to exec command from the host.
As long as you have access to something like the docker socket within your container, you can run any command inside any docker container, doesn't matter whether or not it is linked. For example:
# run a container and link it to `other`
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock \
--link other:other myimage bash -l
bash$ docker exec --it other echo hello
This works even if the link was not specified.
With docker-compose:
version: '2.1'
services:
site:
image: ubuntu
container_name: test-site
command: sleep 999999
dkr:
image: docker
privileged: true
working_dir: "/dkr"
volumes:
- ".:/dkr"
- "/var/run/docker.sock:/var/run/docker.sock"
command: docker ps -a
Then try:
docker-compose up -d site
docker-compose up dkr
result:
Attaching to tmp_dkr_1
dkr_1 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dkr_1 | 25e382142b2e docker "docker-entrypoint..." Less than a second ago Up Less than a second tmp_dkr_1
Example Project
https://github.com/reduardo7/docker-container-access
As "Abdullah Jibaly" said you can do that but there is some security issues you have to consider, also there is sdk docker to use, and for python applications can use Docker SDK for Python

Resources