Docker image for sailsjs development on macosx hangs - node.js

I have a docker image build on Arch Linux (sailsjs-dev) with node and sailsjs which I would like to use for development, mounting the app directory inside the container as follows:
docker run --rm --name testapp -p 1337:1337 -v $PWD:/app \
sailsjs-dev sails lift
$PWD is the directory with the sails project.
This works fine on linux, but if I try to run it on macosx (with docker-machine) it hangs forever at the very beginning, with log level set on silly (in config/log.js):
info: Starting app...
There is no other output, this is all we get.
Note, the same docker image works perfectly also on mac with an express app. What could be peculiar of sail that causes the problem?
I can also add that on a mac docker uses a virtualbox instance named docker machine.

We solved it running npm install from within the docker container:
docker run --rm --name testapp -p 1337:1337 -ti -v $PWD:/app \
sailsjs-dev /bin/bash
npm install --no-bin-links
--no-bin-links avoids the creation of symlinks.

Related

Run docker command into node container

I have a nodejs application inside a docker containter, and I'm trying to run another docker image from the container.
I connected the docker socket to the container, ran the machine, and I went into the containter.
docker run -it -v /var/run/docker.sock:/var/run/docker.sock -w /root node bash
When I write in the terminal docker I get an error:
bash: docker: command not found.
It happens precisely in the specific image of NodeJS, if for example I run such a test
docker run -v /var/run/docker.sock:/var/run/docker.sock \
-ti docker
It works great.
Why can't I run docker in the node image?
This not work because to mount sockets nodejs container must include a docker instance inside it.
Just try another general image other than docker. It also will not work. Search for nodejs images it self include docker. Use that then it will work.
If such image not exist you have to create new image from both docker and nodejs images and add command to start it.

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.

Build jhipster monolithic application using docker container

I have a jhipster monolithic application which I want to build using a docker container. I'm trying to use a jdk docker image and then install nodejs inside it by passing -PnodeInstall. However after sever attempts and trying out different options, I failed to build a docker image of my application. Here is the command which I tried to use:
docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app anapsix/alpine-java:8u162b12_jdk ./gradlew -PnodeInstall bootRepackage -Pdev buildDocker
Please suggest if somebody has tried this before and how to get this working?
Thanks.
As #Meier said, jhipster/jhipster docker image can help avoid setting up ones own workstation to build a JHipster project. I used:
docker run -v .:/home/jhipster/app \
-v ~/.m2:/home/jhipster/.m2 --rm jhipster/jhipster \
./mvnw clean install
Please note that the user running the build will be jhipster(uid=1000) so your files permissions might change to uid 1000.
To build a docker image from your jhipster project run:
$ ./mvnw clean verify -Pprod dockerfile:build
$ docker-compose -f src/main/docker/app.yml up -d
This will build the image and run with docker compose in the background.
If youve made edits and the tests fail, you can put -DskipTests=true on your build command
How can we deploy a application by using Docker in Jhipster
- https://www.youtube.com/watch?v=Jb21o6VLrw4&feature=youtu.be
$ $ mkdir demo
$ cd demo/
$ jhipster
$ jhipster docker-compose
$ ./mvnw -Pprod verify jib:dockerBuild
$ docker-compose -f src/main/docker/app.yml up -d
$ docker image ls -a
$ docker-compose up
$ docker-compose down

how to test an aws lambda function using docker

I am trying to test a simple lambda function using docker on windows.
I already have a docker lambcy/lambda image
But this line:
docker run --rm -v "$PWD":/var/task lambci/lambda
does not work on windows.
What is the appropiate way to do this?
docker run --rm -v "$PWD":/var/task lambci/lambda
The command that you running is targeting linux platform, as for windows platform maybe you can try below instead
docker run --rm -it -v %cd%:/var/task lambci/lambda

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