Download the PHP package diego-ninja/docker without Composer

On this page you can find all versions of the php package diego-ninja/docker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package docker

Manage docker containers with PHP

Latest Version on Packagist Total Downloads PHP Version wakatime PHPStan Level 8 License GitHub Tests Action Status

This package provides a nice way to start docker containers and execute commands on them.

``

Differences

This package is a fork of spatie/docker with some adaptations to fit my particular needs.

As major differences, this package drops php 7.x support and gives the possibility to use the library with already created containers. Also, all methods that return a Symfony process object now accept an $async flag to run the process asynchronously, using the start method instead of run method. Finally, the start method now accepts an optional callable, if present the callable will be called continuously as the container runs, this callable will take the Symfony Process object as its only parameter.

`

Installation

You can install the package via composer:

Usage

You can get an instance of a docker container using

By default, the container will be daemonized, and it will be cleaned up after it exists.

Customizing the docker container

Prevent daemonization

If you don't want your docker being daemonized, call doNotDaemonize.

Prevent automatic clean up

If you don't want your docker being cleaned up after it exists, call doNotCleanUpAfterExit.

Privileged

If you want your docker being privileged, call privileged.

Custom shell

If the bash shell is not available in your docker image, you can specify an alternative shell.

Naming the container

You can name the container by passing the name as the second argument to the constructor.

Alternatively, use the name method.

Mapping ports

You can map ports between the host machine and the docker container using the mapPort method. To map multiple ports, just call mapPort multiple times.

Environment variables

You can set environment variables using the setEnvironmentVariable method. To add multiple arguments, just call setEnvironmentVariable multiple times.

Setting Volumes

You can set volumes using the setVolume method. To add multiple arguments, just call setVolume multiple times.

Setting Labels

You can set labels using the setLabel method. To add multiple arguments, just call setLabel multiple times.

Adding Commands

You can add commands using the setCommands method.

These commands will be placed at the end of to the docker run command.

Add optional arguments

If you want to add optional arguments to the docker run command, use setOptionalArgs method:

These arguments will be placed after docker run immediately.

Automatically stopping the container after PHP exists

When using this package in a testing environment, it can be handy that the docker container is stopped after __destruct is called on it (mostly this will happen when the PHP script ends). You can enable this behaviour with the stopOnDestruct method.

Attaching a network to the container

If you want to attach the container to a docker network, use network method:

Specify a remote docker host for execution

You can set the host used for executing the container. The docker command line accepts a daemon socket string. To connect to a remote docker host via ssh, use the syntax ssh://username@hostname. Note that the proper SSH keys will already need to be configured for this work.

Specify an alternative command to execute

Upon startup of a container, docker will execute the command defined within the container. The command method gives the ability to override to default command to run within the container.

Getting the start command string

You can get the string that will be executed when a container is started with the getStartCommand function

Changing the start command timeout

You can change the timeout for the start command with the setStartCommandTimeout function (the default is 60s).

Available methods on the docker container instance

Executing a command

To execute a command on the container, use the execute method.

You can execute multiple command in one go by passing an array.

To change the process timeout you can pass a third parameter to the execute method (the default is 60s).

The execute method returns an instance of Symfony/Process.

You can check if your command ran successfully using the isSuccessful $method

You can get to the output using getOutput(). If the command did not run successfully, you can use getErrorOutput(). For more information on how to work with a Process head over to the Symfony docs.

Installing a public key

If you cant to connect to your container instance via SSH, you probably want to add a public key to it.

This can be done using the addPublicKey method.

It is assumed that the authorized_keys file is located in at /root/.ssh/authorized_keys. If this is not the case, you can specify the path of that file as a second parameter.

Note that in order to be able to connect via SSH, you should set up a SSH server in your dockerfile. Take a look at the dockerfile in the tests of this package for an example.

Adding files to your instance

Files can be added to an instance with addFiles.

Get the docker inspect information

The json decoded array from the docker inspect command can be retrieved with inspect.

Adding other functions on the docker instance

The Ninja\Docker\ContainerInstance class is macroable. This means you can add extra functions to it.

``

Testing

Before running the tests for the first time, you must build the spatie/docker container with:

`

Next, you can run the tests with:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of docker with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/macroable Version ^2.0
symfony/process Version ^6.0 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package diego-ninja/docker contains the following files

Loading the files please wait ....