Swagger express gives error inside docker container

I have an app that uses the swagger-express-mw library and I start my app the following way:

SwaggerExpress.create({ appRoot: __dirname }, (err, swaggerExpress) => {  
// initialize application, connect to db etc...
}

Everything works fine on my local OSX machine. But when I use boot2docker to build an image from my app and run it, I get the following error:

  • Connection refused when trying to run Kong API Gateway using a docker container
  • Is it possible to get terminal notifications in OSX through a docker container?
  • Docker building fails randomly with Error mounting
  • docker-compose is not setting container_name from environment variable
  • Permission denied when mounting Docker volume in OSX
  • Deployed war file to docker image cannot be accessed from TOMCAT 8 in Ubuntu 16.04
  • /usr/src/app/node_modules/swagger-node-runner/index.js:154
    config.swagger = _.defaults(readEnvConfig(),
                 ^
    
    TypeError: Cannot assign to read only property 'swagger' of [object Object]
    

    My dockerfile looks like this (nothing special):

    FROM node:latest
    
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    COPY package.json /usr/src/app/
    
    RUN npm set progress=false
    RUN npm install
    
    COPY . /usr/src/app
    
    EXPOSE 5000
    
    CMD ["npm", "run", "dev"]
    

    Has anyone else encountered similar situations where the local environment worked but the app threw an error inside the docker container?

    Thanks!

  • Issue mounting docker volume with docker-compose
  • Docker : oci runtime error: exec: “/bin/bash”: stat /bin in windows 7
  • jenkins/docker with environment variables
  • How to setup a development environment for java in unix for each of the team member
  • Set `--net-alias` using Docker API?
  • Limit disk size and bandwidth of a Docker container
  • One Solution collect form web for “Swagger express gives error inside docker container”

    Your issue doesn’t appear to be something wrong with your docker container or machine setup. The error is not a docker error, that is a JavaScript error.

    The docker container appears to be running your JavaScript module in Strict Mode, in which you cannot assign to read-only object properties (https://msdn.microsoft.com/library/br230269%28v=vs.94%29.aspx). On your OSX host, from the limited information we have, it looks like it is not running in strict mode.

    There are several ways to specify the “strictness” of your scripts. I’ve seen that you can start Node.js with a flag --use_strict, but I’m not sure how dependable that is. It could be that NPM installed a different version of your dependent modules, and in the different version they specify different rules for strict mode. There are several other ways to define the “strictness” of your function, module, or app as a whole.

    You can test for strict mode by using suggestions here: Is there any way to check if strict mode is enforced?.

    So, in summary: your issue is not inheritantly a docker issue, but it is an issue with the fact that your javascript environments are running in different strict modes. How you fix that will depend on where strict is being defined.

    Hope that helps!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.