Unable to run Docker image with 'docker-compose up' - docker

I've been trying to start up a development environment for a Docker image that I've found on GitHub, but I've had a great deal of trouble with it. Whenever I run docker-compose up, I'm faced with the following error:
assets_1 | /bin/sh: 1: run-p: not found
assets_1 | error Command failed with exit code 127.
assets_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I then install run-p with the command npm install run-p, but this leads me to the exact same error, and I have no idea how to solve this issue.
I'm unsure if this issue resides in this specific Docker image that I've downloaded from GitHub, but the owner seems to have gotten everything working fairly simply on his end.
Here's my package.json:
{
"name": "sql-language-server",
"displayName": "SQL Language Server",
"description": "SQL Language Server Extension for VSC",
"version": "0.12.0",
"main": "./packages/client/out/extension",
"repository": {
"type": "git",
"url": "git+https://github.com/joe-re/sql-language-server.git"
},
"keywords": [
"sql",
"language-server",
"language-server-protocol",
"lint",
"autocompletion"
],
"bugs": {
"url": "https://github.com/joe-re/sql-language-server"
},
"author": "joe-re <joe.tialtngo#gmail.com>",
"license": "MIT",
"publisher": "joe-re",
"scripts": {
"vsc-compile": "npm run vsc-compile:client && npm run vsc-compile:server",
"vsc-compile:client": "cd ./packages/client && yarn run compile",
"vsc-compile:server": "cd ./packages/server && yarn run prepare-vsc-extension",
"watch": "run-p watch:client watch:server",
"watch:client": "cd ./packages/client && yarn run watch",
"watch:sqlint": "cd ./packages/sqlint && yarn run watch",
"watch:server": "wait-on ./packages/sqlint/dist/src/index.js && cd ./packages/server && yarn run watch:index",
"watch:dev-server:client": "cd ./example/monaco_editor && yarn run webpack:watch",
"watch:dev-server:server": "wait-on ./packages/server/dist/src/index.js && cd ./example/monaco_editor && yarn run start",
"dev": "run-p watch:sqlint watch:server watch:dev-server:client watch:dev-server:server",
"vscode:prepublish": "yarn run vsc-compile"
},
"engines": {
"vscode": "^1.45.1"
},
"activationEvents": [
"onLanguage:sql"
],
"contributes": {
"commands": [
{
"command": "extension.switchDatabaseConnection",
"title": "Switch database connection",
"category": "SQLLanguageServer"
},
{
"command": "extension.fixAllFixableProblems",
"title": "Fix all auto-fixable problems",
"category": "SQLLanguageServer"
},
{
"command": "extension.rebuildSqlite3",
"title": "Rebuild SQLite3 Client",
"category": "SQLLanguageServer"
}
],
"configuration": {
"type": "object",
"title": "sql-language-server configuration",
"properties": {
"sqlLanguageServer.connections": {
"scope": "resource",
"type": "array",
"default": [],
"description": "connection setting"
},
"sqlLanguageServer.lint": {
"scope": "resource",
"type": "object",
"default": {},
"description": "lint setting"
}
}
}
},
"private": true,
"workspaces": [
"packages/*",
"example/*"
],
"devDependencies": {
"npm-run-all": "^4.1.3",
"wait-on": "^5.0.1"
},
"dependencies": {
"electron-rebuild": "^1.11.0",
"run-p": "0.0.0",
"sqlite3": "^4.2.0"
}
}
Here is docker-compose.yaml
version: '3'
services:
assets:
build:
context: .
dockerfile: dockerfile
volumes:
- .:/opt/sql-language-server:rw
command: 'yarn dev' # 'tail -f /dev/null'
ports:
- '3000:3000'
postgres:
image: postgres:10
restart: always
environment:
POSTGRES_DB: postgres_db
POSTGRES_USER: sqlls
POSTGRES_PASSWORD: sqlls
volumes:
- postgres:/var/lib/postgresql/data
mysql:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: mysql_db
MYSQL_USER: sqlls
MYSQL_PASSWORD: sqlls
volumes:
- mysql:/var/lib/mysql
volumes:
postgres:
mysql:
And here is the dockerfile:
FROM node:12
COPY ./package.json yarn.lock /opt/sql-language-server/
COPY ./packages/server/package.json /opt/sql-language-server/packages/server/
COPY ./packages/sql-parser/package.json /opt/sql-language-server/packages/sql-parser/
COPY ./packages/sqlint/package.json /opt/sql-language-server/packages/sqlint/
COPY ./example/monaco_editor/package.json /opt/sql-language-server/example/monaco_editor/
COPY ./example/monaco_editor/.sqllsrc.personal.json /root/.config/sql-language-server/.sqllsrc.json
WORKDIR /opt/sql-language-server
RUN yarn

Related

Rails/React/Yarn: How can I run "yarn start" from the root of my application

I'm creating a rails application from scratch using the following blog which needs me to run rails s and then yarn start in the /client folder of the application (where all the JS and React components will live).
The /client/package.json file has some scripts configured to run a server that detects changes in my react components and reloads the components automatically:
client/package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:3001"
}
I use a program called hivemind which is a Procfile manager and I would like both the rails server process and the yarn process to run together in the same terminal.
I'd like to do something like this in my Profile:
server: bin/rails server
react: yarn start
The problem is that Profile lives in the root of my application and I have to change directory into client and then run yarn start.
TL;DR:
Is there an option with yarn run that you can tell it to run from another folder or read a package.json file in another folder and have it run the script in that file?
You can write cmd arguments in Procfile
try changing react command to
react: cd client && yarn start
It will change the current directory and runs your script
When you run yarn [command] yarn looks for a file locally called package.json. You can add yarn commands inside the "scripts" section of this file. In my own rails app root directory I added a "start" command that did what Sumanth's answer does but now I can just have
react: yarn start
in my Procfile.
Below is the edited version of my package.json file in my app's root path:
{
"name": "create-repack-app",
"version": "1.0.0",
"scripts": {
"build": "cd client && npm install --only=dev && npm install && npm run build && cd ..",
"deploy": "cp -a client/build/. public/",
"heroku-postbuild": "npm run build && npm run deploy && echo 'Client Built'",
"start": "cd client && yarn start"
},
"keywords": [],
"author": "",
"license": "ISC"
}

Can't connect to other containers inside docker network

I have a few containerized projects I would like to talk to each other into a network called 'dev_network'.
I would expect to be able to start up both containers and be able to ping them from inside the containers..
E.g. I should be able to ping foo from bar, but I cannot.
root#75cba11f489c:/# ping bar
ping: bar: Name or service not known
These projects live in separate folders, but I would like them to connect to the same network and be able to talk to each other.
Here's a simple configuration that shows the problem
There's a foo service and a bar service.
Here is the Dockerfile for the foo service:
FROM debian:stretch-slim
RUN set -x && apt-get update && apt-get install -y apt-utils
RUN set -x && apt-get install -y iputils-ping
ENTRYPOINT ["/bin/bash"]
The Dockerfile for the bar service is identical:
FROM debian:stretch-slim
RUN set -x && apt-get update && apt-get install -y apt-utils
RUN set -x && apt-get install -y iputils-ping
ENTRYPOINT ["/bin/bash"]
Here's the docker-compose.yml for the foo service:
version: '3.5'
services:
foo:
image: foo
build:
context: .
dockerfile: Dockerfile
networks:
default:
name: dev_network
driver: bridge
And the only slightly different docker-compose.yml for the bar service:
version: '3.5'
services:
bar:
image: bar
build:
context: .
dockerfile: Dockerfile
networks:
default:
name: dev_network
driver: bridge
Starting up the foo service:
docker-compose build; docker-compose run foo
Building foo
Step 1/4 : FROM debian:stretch-slim
---> bd04d03c4529
Step 2/4 : RUN set -x && apt-get update && apt-get install -y apt-utils
---> Using cache
---> e53a746ba26b
Step 3/4 : RUN set -x && apt-get install -y iputils-ping
---> Using cache
---> 63e2377e85d7
Step 4/4 : ENTRYPOINT ["/bin/bash"]
---> Using cache
---> c304ddfa1035
Successfully built c304ddfa1035
Successfully tagged foo:latest
root#680d2ef987d2:/#
Starting the bar service looks identical:
docker-compose build; docker-compose run bar
... same as above mostly
After starting the two services, the networks look like this:
docker network ls
NETWORK ID NAME DRIVER SCOPE
95c4f247d652 bridge bridge local
13e26f1434ba dev_network bridge local
5fc09d998133 host host local
23acbaf51f4e none null local
And inspecting the dev_network shows:
docker network inspect dev_network
docker network inspect dev_network
[
{
"Name": "dev_network",
"Id": "13e26f1434ba74c16964d29ceaa73eafd9df09622a1801c9fc9e49d2552273de",
"Created": "2019-01-07T22:08:25.3589996Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.28.0.0/16",
"Gateway": "172.28.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"75cba11f489c8ad01ece0c5348d150fa6e64cdb5da31fe791e4f1c17284326c8": {
"Name": "foo_foo_run_7faa90f193d0",
"EndpointID": "f133df00bec7849c700669ef4395c5c45e82f6b6ab462f4f988508ac78d87d4b",
"MacAddress": "02:42:ac:1c:00:02",
"IPv4Address": "172.28.0.2/16",
"IPv6Address": ""
},
"807fbb8527aacc5d5ac7ef35091ae589aa85a18401f99eb558bfbf07fa5826ef": {
"Name": "bar_bar_run_45964b29fb9a",
"EndpointID": "99001203fdb6f3f1e33b95cad53648c2a029dcda269a687f81ba443656d3d3c2",
"MacAddress": "02:42:ac:1c:00:03",
"IPv4Address": "172.28.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "dev_network",
"com.docker.compose.project": "bar",
"com.docker.compose.version": "1.23.2"
}
}
]
I found a way to do what I want, but it doesn't seem to be configurable via docker-compose.yml
I have to start the services in this way:
docker-compose build; docker-compose run --name foo --rm foo
and
docker-compose build; docker-compose run --name bar --rm bar
Then I can ping between them and the network looks like this:
docker network inspect dev_network
...
"Containers": {
"94ae3d8789c2bbf77b1fd2b19a11a00c4fb32462cd20e47b36f0d8c910901c54": {
"Name": "foo",
"EndpointID": "c024a3ff8bf8d98454b05c45e95267508589868a20269552c8bae393d8bd5392",
"MacAddress": "02:42:ac:1c:00:02",
"IPv4Address": "172.28.0.2/16",
"IPv6Address": ""
},
"d310999e759d000b9330177cf4ca483eafd66bcced333b12fe4ff5d0cebdefbc": {
"Name": "bar",
"EndpointID": "6cf92bd9f463a0c1d3e2fd749a8d9e8ae3f13219e1f29a01061a05e040cd485c",
"MacAddress": "02:42:ac:1c:00:03",
"IPv4Address": "172.28.0.3/16",
"IPv6Address": ""
}
},

Cannot access web server using docker

I used the following command to run the container :
docker run -p 3333:3333 -d maill/node-web-app
Here is the result of docker ps :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f26270107bfa maill/node-web-app "npm run dev" 49 seconds ago Up 46 seconds 0.0.0.0:3000->3000/tcp musing_fermi
However when I try to access webserver on host using localhost:3333 it doesn't work.
I am using windows 10 pro.
docker logs musing_fermi shows:
DONE Compiled successfully in 3541ms16:04:50 | OPEN localhost:3000
Dockerfile :
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 3333
CMD [ "npm", "run", "dev" ]
package.json :
{
"name": "webapp-pst-horizon",
"version": "1.0.0",
"description": "Webapp pour les formations enedis",
"author": "Léo Coletta",
"private": true,
"scripts": {
"dev": "cross-env HOST=0.0.0.0 PORT=3333 nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
},
"dependencies": {
"#nuxtjs/axios": "^5.3.1",
"#nuxtjs/proxy": "^1.2.4",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"cookie": "^0.3.1",
"js-cookie": "^2.2.0",
"nuxt": "^1.4.1",
"vuetify": "^1.0.19",
"webpack": "^3.1.0"
},
"devDependencies": {
"babel-eslint": "^8.2.3",
"cross-env": "^5.2.0",
"eslint": "^4.9.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-vue": "^4.5.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2"
}
}
Based on what you have in the question so far, and that you have OPEN localhost:3000 coming from your container logs, I'd guess your application is listening on localhost. This is != localhost outside the container. You need to configure your application to listen on 0.0.0.0 inside the container.
To go along with johnharris85's answer, add the following to your package.json:
From nuxt documentation on "How to edit HOST and PORT?"
You can configure the PORT with 3 different ways:
...
...
Via a nuxt config in the package.json:
Inside your package.json:
"config": {
"nuxt": {
"host": "0.0.0.0",
"port": "3333"
}
},
"scripts": {
"dev": "nuxt"
}

Ionic project built with docker do not load static files

I have an Ionic project already working and running. I wanted to dockerize it so I wrote and added Dockerfile and .dockerignore to it manually. My project structure looks like following:
My package.json:
{
"name": "example",
"version": "1.1.1",
"description": "example: An Ionic project",
"dependencies": {
"angular-messages": "^1.5.1",
"gulp": "^3.5.6",
"gulp-concat": "^2.2.0",
"gulp-minify-css": "^0.3.0",
"gulp-rename": "^1.2.0",
"gulp-sass": "^2.0.4"
},
"devDependencies": {
"bower": "^1.3.3",
"gulp-util": "^2.2.14",
"shelljs": "^0.3.0"
},
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"android"
]
}
My bower.json:
{
"name": "HelloIonic",
"private": "true",
"dependencies": {
"angular": "~1.3.1",
"angular-route": "~1.3.1",
"angular-cookies": "~1.4.0",
"bootstrap": "~3.3.0",
"bootstrap-material-design": "~0.1.5",
"jquery": "~2.1.1",
"ngDialog": "~0.3.3",
"underscore": "~1.7.0",
"ionic": "^1.2.4",
"angular-resource": "^1.5.2",
"angular-google-chart": "^0.1.0",
"angular-ui-router-styles": "^1.1.0",
"angular-audio": "^1.7.2"
},
"resolutions": {
"angular": "~1.3.1"
}
}
My Dockerfile:
FROM node:4.0
COPY . /www/app
RUN npm install -g ionic cordova
RUN npm install -g bower
RUN npm install -g gulp
WORKDIR /www/app
RUN npm install
RUN echo '{"allow_root":true}' > /root/.bowerrc
RUN bower install
EXPOSE 8100 35729
ENTRYPOINT ["ionic"]
CMD ["serve", "--all", "--port", "8100", "--livereload-port", "35729"]
And .dockerignore:
Dockerfile
config.xml
.sass-cache
.editorconfig
.io-config.json
.dockerignore
hooks/
platforms/
node_modules/
resources/
plugins/
www/css/*.css
*.zip
*.tar*
It is built successfully (I guess, as there are no errors) but when I execute docker build -t ionic-preview . but when I run it with docker run -p 8100:8100 -it ionic-preview - > it runs but no static files are loaded.
Is there anything wrong with my dockerfile? Or what is the issue?
UPDATE:
When normally I run my application, I see like following:
With docker I see this:
You did not share your data yet as in: -v /src/webapp:/webapp
So you could do:
docker run -p 8100:8100 -v /src/webapp:/webapp -it ionic-preview
Change the maps to your maps.
Source: https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume

Docker container communication on the same net not work

I have 3 different docker container (on windows 10) on the same network (core_net), but when use curl on backend
-curl localhost:7000
the response is:
"curl: (7) Failed to connect to localhost port 7000: Connection refused"
Why?
Docker commands:
Frontend:
docker run -itd --name dam --net=core_net -p 3000:3000 DAM
Backend:
docker run -itd --name core --net=core_net -p 6000:6000 -p 7000:7000 -p 8000:8000 -p 9000:9000 SG
Database:
docker run --name mongodb -p 27017:27017 -d mongo:3
These is the dockerfile:
Frontend:
FROM node:4.5.0
# Create app directory
RUN mkdir -p /DAM
WORKDIR /DAM
# Install app dependencies
COPY package.json /DAM
RUN npm install
RUN npm install gulp -g
RUN echo '{ "allow_root": true }' > /root/.bowerrc
RUN npm install bower -g
# Bundle app source
COPY . /DAM
ENV PORT 3000 3001
EXPOSE $PORT
CMD ["gulp", "serve"]
and
Backend:
FROM node:4.5.0
RUN npm install nodemon -g
# Create app directory
RUN mkdir -p /SG
WORKDIR /SG
# Install app dependencies
COPY package.json /SG
RUN npm install
# Bundle app source
COPY . /SG
ENV PORT 6000 7000 8000 9000
EXPOSE $PORT
CMD ["npm", "start"]
Inside container the ping works and the inspect is this:
$ docker network inspect core_net
{
"Name": "core_net",
"Id": "1f9e5426abe397d520360c05c95fee46fe08c98fe5c474c8b52764e491ea23e7",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Containers": {
"3d3b8780fba2090b1c2feaddf2e035624529cf5474ad4e6332fe7071c0acbd25": {
"Name": "core",
"EndpointID": "f0a6882e690cf5a7deedfe57ac9b941d239867e3cd58cbdf0ca8a8ee216d53a9",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"bb6a6642b3a7ab778969f2e00759d3709bdca643cc03f5321beb9b547b574466": {
"Name": "dam",
"EndpointID": "b42b802e219441f833d24971f1e1ea74e093f56e28126a3472a44750c847daa4",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"cf8dd2018f58987443ff93b1e84fc54b06443b17c7636c7f3b4685948961ba3f": {
"Name": "mongodb",
"EndpointID": "be02d784cbd46261b7a53d642102887cafa0f880c8fe08086b9cc026971ea1be",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
Commnication between mongodb and core work but between dam and core not work.
what's the problem?
To connect to another container with in an network you can not use localhost, but cou can use the name of the conatiner you want to reach. e.g. curl core:7000
To use localhost the conatiners have to share their network stack. You can do that with --network container:core
And if you dont have to reach the backend from outside of docker, it is enought to only expose the ports, and not to publish them

Resources