Cannot start Spark in Docker container - apache-spark

I'm trying to run a Spark instance using Docker (on Windows) following this explanation: https://github.com/sequenceiq/docker-spark
I was able to:
Pull the image
Build the image
I had to download the Github repository with the Dockerfile though and specify that in the build command. So instead of docker build --rm -t sequenceiq/spark:1.6.0 . I had to run docker build --rm -t sequenceiq/spark:1.6.0 /path/to/dockerfile
However when I try to run the following command to run the container:
docker run -it -p 8088:8088 -p 8042:8042 -p 4040:4040 -h san
dbox sequenceiq/spark:1.6.0
I get the error:
Error response from daemon: Container command '/etc/bootstrap.sh' not found or does not exist.
I tried copying the bootstrap.sh file from the Github repository to the /etc directory on the VM but that didn't help.
I'm not sure what went wrong, any advice would be more than welcome!

It is probably an issue with the build context because you changed the path to the Dockerfile in your build command.
Instead of changing the path to the Dockerfile in the build command, try cd'ing into that directory first and then running the command. Like so:
cd /path/to/dockerfile
docker build --rm -t sequenceiq/spark:1.6.0 .

Related

Change default run command of VSC Docker extension

When right-clicking on an image in Microsoft's Docker plugin and selecting run it executes the following command:
docker run --rm -d -p 3000:3000/tcp falaen:latest
I would like it to run the following command instead:
docker run --restart=always -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -p 3000:3000 -d falaen
I have tried to modify the run command in the Dockerfile but without success.
Of course, I can run the command manually in the terminal each time but it would be nicer to simply right click on the image and then run it.
You could try adding this line to your VSCode's settings.json, to override the default configuration of the command.
"docker.commands.run": "docker run --restart=always -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -p 3000:3000 -d ${tag}"
This will run the command using any image you select.

Parent Docker Containers using Docker in Docker

I am working on a jenkins ssh agent for my builds
I want to have docker installed so it can run and build docker images
I currently have the following in my Dockerfile
RUN curl -fsSL get.docker.com -o /opt/get-docker.sh
RUN chmod +x /opt/get-docker.sh
RUN sh /opt/get-docker.sh
This works fine when I run docker with
docker run <image> -v /var/run/docker.sock:/var/run/docker.sock
Issue I'm having is when I run docker ps with in the container, it shows all my parent containers as well, is there a way to prevent this?
If you mount the host's /var/run/docker.sock your docker client will connect to the host's docker daemon, and so see everything that is running on the host.
To make it so your containers can run docker in a way that appears isolated from the host you should investigate Docker-in-docker.

Running commands for docker container

This is how I'm running a command in a docker container:
$ docker run -it --rm --name myapp myimage:latest
$ node --version
Is it possible to to run this as one command? Can I pass a command to the docker run-command?
Something like
$ docker run -it --rm --name myapp myimage:latest "node --version"
Of course this is just a simple example. Later I will execute some more complex commands...
The "docker run" command essentially will make the container run, and execute the "CMD" or "ENTRYPOINT" in the Dockerfile. Unless - the command in your dockerfile does not run a command prompt - "running" the container may not get you the prompt.
For example if you want that everytime you run the container - it gets you the command prompt then have the line below in your Dockerfile.:
CMD ["bash"]
If you want to run the same commands everytime you run the command - then you could create a script file with your commands, copy them to the container, and execute the script file as a CMD directive.
The general form of the command is actually:
docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
See documentation for more details.
The answer to the minimal example in your question is simply:
docker run -it --rm --name myapp myimage:latest node --version
If you want to run multiple commands in sequence, you can:
Run container
Execute your commands against the running container using docker exec
Remove it
I am having some trouble understanding what you are trying to do.
you can just :
docker run -d --name myapp myimage:latest -f /dev/null and then your container is up and you can run any command in it
you can pass a command to the docker run but once the command ends the container will exit

How to get docker run to take the directory from the client machine to the host container?

My goal is to compile some code using maven from my project directory on my docker client machine using docker. (mvn compile running in a docker container).
Assume my maven image is called mvn-image and my project directory is project-dir.
If I had the docker host running on the same machine as the docker client - then I could mount a volume with something similar to:
mvn -v /projects/project-dir:/workdir -i mvn-image mvn compile
But here is the tricky bit. My docker client is on a different machine to the host machine. I'm trying not to build and and push and run a image built from my project directory - I want the convenience of the docker one-liner.
I also know I can run the container - and do a cp to get the files in there. But with that I still don't get the one-liner that I would with the docker-copy mount volume.
My question is: **How to get docker run to take the directory from the client machine to the host container? **
Sending local data is not really a feature of docker run. Other commands like docker build, docker import and docker cp are able to send local data across from client to host. docker run can send stdin to the server though.
Docker build
A docker build will actually run on the remote host your client points at. The "build context" is sent across and then everything is run remotely. You can even run the maven build as part of the build:
FROM mvn-image
COPY . /workdir
RUN mvn compile
CMD ls /workdir
Then run
docker build -t my-mvn-build .
You end up with an image on the remote host with your build in it. There's no local-build/push/remote-build steps.
Docker run Stdio
docker run can do standard Unix IO, so piping something into a command running in a container works like so:
tar -cf - . | docker run -i busybox sh -c 'tar -xvf -; ls -l /'
I'm not sure how that's going to work with the mvn command that you supplied to run a container, under the normal Docker client it would be something like:
tar -cf - -C /projects/project-dir . | \
docker run mvn-image mvn compile sh -c 'tar -xvf - -C /workdir; mvn compile'
Storage Plugins
Otherwise you could mount the data on the host from the client somehow. There are NFS and sshfs storage plugins.
Rsync
Using rsync or something similar to send your project to the Docker host would be a lot more efficient over time.
Docker cp script
The docker cp is a fairly simple solution though. If you put it in a script, yet get a "one liner" to run.
#!/bin/sh
set -uex
cid=$(docker create mvn-image mvn compile)
docker cp /projects/project-dir $cid/workdir
docker start $cid
docker logs -f $cid
you'll have to use a Docker Volume Plugin to mount the shared / network folder.
https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-shared-storage-volume-as-a-data-volume

Cannot finde module 'express' (node app with docker)

I'm a newbie with Docker and I'm trying to start with NodeJS so here is my question..
I have this Dockerfile inside my project:
FROM node:argon
# Create app directory
RUN mkdir -p /home/Documents/node-app
WORKDIR /home/Documents/node-app
# Install app dependencies
COPY package.json /home/Documents/node-app
RUN npm install
# Bundle app source
COPY . /home/Documents/node-app
EXPOSE 8080
CMD ["npm", "start"]
When I run a container with docker run -d -p 49160:8080 node-container it works fine..
But when I try to map my host project with the container directory (docker run -p 49160:8080 -v ~/Documentos/nodeApp:/home/Documents/node-app node-cont) it doesn't work.
The error I get is: Error: Cannot find module 'express'
I've tried with other solutions from related questions but nothing seems to work for me (or I know.. I'm just too rookie with this)
Thank you !!
When you run your container with -v flag, which mean mount a directory from your Docker engine’s host into a container, will overwrite what you do in /home/Documents/node-app,such as npm install.
So you cannot see the node_modules directory in the container.
$ docker run -d -P --name web -v /src/webapp:/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the container at /webapp. If the path /webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.
mount a host directory as a data volume.As what the docs said,the pre-existing content of host directory will not be removed, but no information about what's going on the exist directory of the container.
There is a example to support my opinion.
Dockerfile
FROM alpine:latest
WORKDIR /usr/src/app
COPY . .
I create a test.t file in the same directory of Dockerfile.
Proving
Run command docker build -t test-1 .
Run command docker run --name test-c-1 -it test-1 /bin/sh,then your container will open bash.
Run command ls -l in your container bash,it will show test.t file.
Just use the same image.
Run command docker run --name test-c-2 -v /home:/usr/src/app -it test-1 /bin/sh. You cannot find the file test.t in your test-c-2 container.
That's all.I hope it will help you.
I recently faced the similar issue.
Upon digging into docker docs I discovered that when you run the command
docker run -p 49160:8080 -v ~/Documentos/nodeApp:/home/Documents/node-app node-cont
the directory on your host machine ( left side of the ':' in the -v option argument ) will be mounted on the target directory ( in the container ) ##/home/Documents/node-app##
and since your target directory is working directory and so non-empty, therefore
"the directory’s existing contents are obscured by the bind mount."
I faced an alike problem recently. Turns out the problem was my package-lock.json, it was outdated in relation to the package.json and that was causing my packages not being downloaded while running npm install.
I just deleted it and the build went ok.

Resources