Combine docker files. thrift and nodejs - node.js

I'm a web dev and I use node. A colleague has added code to my branch that uses the thrift npm package. Although thrift is a npm package, it needs to be installed on the local machine still for the package to be used. I do not have apache thrift installed and cannot run the code. I will eventually have to deploy this code so I'd like to look into creating a docker container that has thrift available and the nodejs code can run in that container using the thrift installation.
I cannot find a container for this purpose. There is an official docker image with the thrift library, but that seems like it only runs thrift files. there is also an the node container of course, any way I can combine the two?

Check this docker file which contains both nodejs and thrift. I directly build this image from appache/thift which is official docker image of thrift and install nodejs and npm.
FROM apache/thrift
RUN apt-get update && apt-get install -y --no-install-recommends curl sudo
RUN curl --silent --location https://deb.nodesource.com/setup_8.x | sudo bash - && \
apt-get install --yes nodejs && \
apt-get install --yes build-essential
RUN apt-get install --yes npm
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/bin/bash"]
Build command:
docker build -t thrift-node .
Run command
docker run --name test-thrift - -p 3000:3000 --rm -it thrift-node
Verify version command
thrift -version
nodejs -v
npm -v

Related

Web app not accessible while using yarn in docker

I am trying to run a web app inside docker via yarn. Here's the docker file
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get upgrade -y
ENV TZ=Pacific/Auckland
RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
RUN apt-get install curl -y
RUN apt-get install npm -y
RUN apt-get install git -y
RUN npm cache clean -f
RUN npm install -g n
RUN n stable
RUN apt remove cmdtest -y
RUN apt remove yarn -y
RUN npm install -g yarn -y
RUN git config --global url."https://".insteadOf git://
EXPOSE 8080
COPY . .
RUN yarn
CMD yarn start
When I run yarn start as a non-docker the web app is accessible via localhost:8080
However when I start the docker instance via docker run -p 8080:8080 -itd webapp:latest & launch web browser & type in http://localhost:8080 the webapp isn't accessible.
Running docker logs against the container doesn't show any errors.
When I run curl, here is the error I see
curl "http://localhost:8080"
curl: (56) Recv failure: Connection reset by peer
I've no clue what is going on. Please could I request help to fix this problem.
the IP had to be bound on multiple interfaces for this to start working

Using docker rootless with new version

There is a new rootless capabilities on docker new release,
https://docs.docker.com/engine/security/rootless/
We need to run it in our environments and provide using Dockerfile
I try the following
FROM debian:10.6
RUN apt-get -y update && apt-get -y install git curl
ENV USER=user
RUN curl -fsSL https://get.docker.com/rootless | sh
RUN PATH=/home/testuser/bin:$PATH
RUN PATH=$PATH:/sbin
RUN DOCKER_HOST=unix:///run/user/1001/docker.sock
RUN docker --help
When running it I got error:
# Installing stable version 20.10.0
Refusing to install rootless Docker as the root user
The command '/bin/bash -c curl -fsSL https://get.docker.com/rootless | sh' returned a non-zero code: 1
How can I run it as unprivileged user using docker?
Why? We have some unique env where we providing our "tools" using docker (like go, k8s binary etc) but not providing docker itself ( docker cli / daemon etc) to the env.
Now docker support rootless privileges and we want to add the binary and the way to execute the docker command build push.

'node --no-deprecation': No such file or directory when running global npm command in ubuntu docker container

I'm trying to install the npm package #stoplight/cli globally onto a docker image for use in a GitHub action. The docker image builds successfully, but when I call stoplight from /bin/bash with stoplight, I get the dreaded /usr/bin/env: 'node --no-deprecation': No such file or directory error.
I know there has been a lot of questions of this exact error, but so far none of the solutions have worked12.
I tried:
Creating symlink with ln -s /usr/bin/nodejs /usr/bin/node
Installing nodejs-legacy instead
My Dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get -y install git curl
RUN apt-get install -y nodejs
RUN npm install -g #stoplight/cli#3.0.1
ENTRYPOINT ["bash", "stoplight --version"]
EDIT: ** I also tried doing this with the official debian "node" image as base, and it was the same issue.
Any help appreciated
we've released a new version of the CLI that should hopefully resolve the issue for you. The following dockerfile should work!
FROM ubuntu:latest
RUN apt-get update
RUN apt-get -y install curl
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g #stoplight/cli#3.0.4
ENTRYPOINT ["stoplight"]

Docker container with Docker and node: Not working with multi-stage

I would like to have a docker container for a CI-step that has docker and node installed.
I thought it would be the perfect use-case to use the multistage build.
I have a new docker version Docker version 18.09.3, build 774a1f4 and I tried this Dockerfile, but to no avail:
FROM docker:18.09.3
FROM node:8
CMD ['bash']
The resulting image has node-stuff such as npm installed, but no docker things... Any ideas how to proceed here?
Thanks a lot!
Update
I changed the Dockerfile to this, which also does not work (docker is not installed in the container):
FROM docker:18.09.3
FROM ubuntu:latest
USER root
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get -y install nodejs
CMD [ "node" ]
Update2
This Dockerfile does what I need, but it is not with multi-stage (which I would have liked to try here)
FROM docker:18.09.3
USER root
RUN apk update
RUN apk add --update nodejs nodejs-npm
CMD [ "node" ]

Issue running Gulp on Docker

I have the following Dockerfile
FROM debian:jessie
MAINTAINER Ewan Valentine <ewan#theladbible.com>
WORKDIR /tmp
RUN apt-get update -y && \
apt-get install -y \
curl
RUN curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
RUN apt-get install --yes nodejs
VOLUME ["/var/www/admin/src"]
RUN mkdir -p /var/www/admin/src
WORKDIR /var/www/admin/src
RUN npm install -g gulp
ENTRYPOINT ["gulp"]
However, when I run $ docker-compose run gulp I get the following error:
[10:47:49] Local gulp not found in /var/www/admin/src
[10:47:49] Try running: npm install gulp
I'm using docker-compose and this container is linked to a volume where the source code is kept, which all runs fine otherwise.
I was liking to the wrong volume! Sorted now.

Resources