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:

  • why failed to forward public ip to docker NAT ip
  • How do I connect to a web app running on an image on docker hub?
  • Importing modules from jupyter notebook to another jupyter notebook shared on gist
  • How to create concourse loop for repetitive resources and jobs?
  • Writable folder permissions in docker
  • Map data container volume to volume
  • /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?


  • PULL Docker container/image
  • Setting-up containers reverse proxy
  • docker-compose up “Cannot start service frontend: oci runtime error: not a directory”
  • How to use docker with gradle while having private docker registry server
  • Mounting user SSH key in container
  • Run jhipster-registry in production
  • 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.