# How to interact with stockfish running in docker Create a file called `stockfish` with the following contents: ```sh #!/bin/sh nc localhost 23249 ``` Give it executable permissions with: ``` chmod +x stockfish ``` Now you can run the following to start stockfish: ``` docker run -d --rm --name stockfish -p 23249:23249 -p 23250:23250 -v $(pwd):/stockfish:ro -w /stockfish stockfish ``` This will start a stockfish instance that will listen on port 23249 for commands. You can now run `./stockfish` to interact with the stockfish instance. ``` ./stockfish uci isready quit ``` More examples of stockfish engine interaction are: ``` ./stockfish uci isready ucinewgame position startpos moves e2e4 e7e5 g1f3 g8f6 go depth 20 quit ``` For more information about stockfish, see the [stockfish github page](https://github.com/official-stockfish/Stockfish). ## PyChess Example ```python import chess import chess.engine stockfish = chess.engine.SimpleEngine.popen_uci("./stockfish") board = chess.Board() while not board.is_game_over(): result = stockfish.play(board, chess.engine.Limit(time=0.1)) board.push(result.move) print(board, "\n") stockfish.quit() ```