Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need example on how to pass params #47

Open
vitamon opened this issue May 18, 2018 · 1 comment
Open

Need example on how to pass params #47

vitamon opened this issue May 18, 2018 · 1 comment

Comments

@vitamon
Copy link

vitamon commented May 18, 2018

Hi!
It is not clear how to pass params to match with 'docker run' command:
how to pass port mappings, '--shm-size' etc. Please add some examples on it.

@ericmacfarland
Copy link

ericmacfarland commented Jun 13, 2018

@vitamon you may find the docker engine api docs helpful.

It's worth noting that while the docker CLI supports docker run ..., the engine requires you to first create a container (where you would specify your options), and then start that container.

For example, you could start a mysql container on port 3306 with a shm size of 128MB using the following code:

const { Docker } = require('node-docker-api');
const docker = new Docker({ socketPath: '/var/run/docker.sock' });

docker.container
    .create({
        name: 'mysql', // equivalent to --name=mysql for `docker run`
        Image: 'mysql:5.7.19',
        Env: ['MYSQL_ROOT_PASSWORD=rootpassword', 'MYSQL_DATABASE=example_database'], // Boilerplate for mysql
        HostConfig: {
            PortBindings: {
                '3306/tcp': [
                    {
                        HostIp: '0.0.0.0',
                        HostPort: '3306' // Bind the container to port 3306 on the host
                    }
                ]
            },
            ShmSize: 128000000 // Set the shm size to 128MB
        }
    })
    .then(container => container.start());

Note: If you do not have the mysql:5.7.19 image locally, you must first pull it with docker pull mysql:5.7.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants