Video Lesson: Manage files and folders within Docker containers

Manage files and folders within Docker containers

Learn how to manage files and folders between your host machine and Docker containers.


Lesson Content

You don’t need bidirectional synchronization for every file or folder you want to change. You can open a Bash shell inside the Docker container with bin/bash:

bin/bash

You’re now inside the container, so you can inspect its filesystem and edit files directly. For example, you can open pub/index.php:

vi pub/index.php

When you’re finished, exit the shell with exit:

exit

You’re back on your host machine.

If you only need to run one command inside the container, use bin/cli instead of opening an interactive shell. Pass the command after bin/cli, and it runs directly in the container:

bin/cli vi pub/index.php

When you quit the editor, you return directly to your host machine.

You can also edit a file on the host and copy it into the container. For example, open src/pub/index.php on your host, add the following line, and save the file:

die('hi there!');

The pub directory isn’t bidirectionally synchronized in the Docker Compose configuration, so copy it into the container manually:

bin/copytocontainer pub

This copies the entire pub folder into the container and corrects any ownership or permission issues. Refresh your Magento page to confirm that the hi there! message appears.

The vendor folder is another directory that isn’t bidirectionally synchronized. Composer generates this folder as a build artifact, and synchronizing all of its files would have a significant performance impact. Instead, copy it back to your host whenever you run composer install or composer update and need the files locally.

Use bin/copyfromcontainer followed by the folder name:

bin/copyfromcontainer vendor

The command can take a few moments because it copies the entire vendor folder and all of its subfolders to your host machine. Once it finishes, you can inspect the local vendor directory and access the Composer packages and Magento modules there.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Log in for AI tutor access.

Comments

Join the discussion!

Notes

Keep track of what you learn!