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:

  • How to use --volume option with Docker Toolbox on Windows?
  • After stopping docker containers , previously running containers cannot be started
  • How to create a volume from a local path in a Dockerfile?
  • How-to: Dockerfile layer(s) reuse / reference
  • Is it possible to connect ipc namespeces with docker compose
  • Docker Apache graceful shutdown
  • /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!

  • Is it possible to share memory between docker containers?
  • In dockerfile after create or copy file or directory in RUN statement it not/doesn't exists
  • How to prevent docker containers from consuming all CPU?
  • How to generate a Postgresql Dump from a Docker container?
  • Run apache/php/nginx in background Docker container
  • Is it possible in some way to use POSIX semaphores between Docker containers or between a container and the host?
  • 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.